LeetCode-Isomorphic Strings
2015-05-03 21:11
190 查看
用HashMap的 containsKey 和 containsValue 匹配
public class Solution {
public boolean isIsomorphic(String s, String t) {
if(s==null||s.length()==0)
return true;
HashMap<Character, Character> mapS=new HashMap<Character, Character>();
for(int i=0;i<s.length();i++){
char sChar=s.charAt(i);
char tChar=t.charAt(i);
if(mapS.containsKey(sChar)&&mapS.get(sChar)==tChar)
continue;
if((!mapS.containsKey(sChar))&&(!mapS.containsValue(tChar))){
mapS.put(sChar, tChar);
}else {
return false;
}
}
return true;
}
}
public class Solution {
public boolean isIsomorphic(String s, String t) {
if(s==null||s.length()==0)
return true;
HashMap<Character, Character> mapS=new HashMap<Character, Character>();
for(int i=0;i<s.length();i++){
char sChar=s.charAt(i);
char tChar=t.charAt(i);
if(mapS.containsKey(sChar)&&mapS.get(sChar)==tChar)
continue;
if((!mapS.containsKey(sChar))&&(!mapS.containsValue(tChar))){
mapS.put(sChar, tChar);
}else {
return false;
}
}
return true;
}
}
相关文章推荐
- [LeetCode] Isomorphic Strings - 字符串操作:数组计数字符个数问题
- LeetCode 205:Isomorphic Strings
- 205.[Leetcode]Isomorphic Strings
- LeetCode-E-Isomorphic Strings
- Isomorphic Strings leetcode 205
- leetcode--Isomorphic Strings
- [LeetCode]Isomorphic Strings
- LeetCode----Isomorphic Strings
- [Leetcode]Isomorphic Strings
- [leetcode]Isomorphic Strings
- leetcode笔记:Isomorphic Strings
- leetcode 205: Isomorphic Strings
- LeetCode之Isomorphic Strings
- LeetCode205 Isomorphic Strings同构字符串
- LeetCode题解:Isomorphic Strings
- LeetCode(44)- Isomorphic Strings
- 关于LeetCode中Isomorphic Strings一题的理解
- [leetcode]Isomorphic Strings
- leetcode--Isomorphic Strings
- LeetCode(44)- Isomorphic Strings