题目:
1、s中同一个字符要映射到t中的同一个字符;
2、s中通一个字符不能映射到t中的同一个字符——》t中的同一个字符要映射到s中的同一个字符
so需要s到t判断一下,t到s再判断一下;
public class Solution {
public boolean isIsomorphic(String s, String t) {
if (s.length() != t.length()) {
return false;
}
return isSingleIsomorphic(s,t) && isSingleIsomorphic(t, s);
}
private boolean isSingleIsomorphic(String s, String t) {
// TODO Auto-generated method stub
HashMap<Character, Character> map = new HashMap<Character, Character>();
char ch1, ch2;
for (int i = 0; i < s.length(); i++) {
ch1 = s.charAt(i);
ch2 = t.charAt(i);
if (!map.containsKey(ch1)) {
map.put(ch1, ch2);
}
else {
if (map.get(ch1) != ch2) {
return false;
}
}
}
return true;
}
}