两个哈希表存储字符的映射关系,如果前面字符的映射关系和后面的不一样则返回false
class Solution {public boolean isIsomorphic(String s, String t) {if (s.length() != t.length()) {return false;}int length = s.length();Map<Character, Character> s2t = new HashMap<>();Map<Character, Character> t2s = new HashMap<>();for (int i = 0; i < length; i++) {char sch = s.charAt(i);char tch = t.charAt(i);if (s2t.containsKey(sch) && s2t.get(sch) != tch) {return false;} else {s2t.put(sch, tch);}if (t2s.containsKey(tch) && t2s.get(tch) != sch) {return false;} else {t2s.put(tch, sch);} }return true;}}