严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Is Somorphic高频题需要bug free

Go down

Is Somorphic高频题需要bug free Empty Is Somorphic高频题需要bug free

Post by Admin Sat Oct 21, 2017 4:36 pm

public boolean isSomorphic(String s,String t){
if(s==null||t==null){
return false;
}
if(s.length()!=t.length()){
return false;
}
HashMap<Character,Character> map=new HashMap<Character,Character>();
for(int i=0;i<s.length();i++){
char c1=s.charAt(i);
char c2=t.charAt(i);
if(map.containsKey(c1)){
if(map.get(c1)!=c2){
return false;
}
}else{
if(map.containsValue(c2)){
return false;
}
map.put(c1, c2);
}
}
return true;
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum