解题思路:
(1)使用unordered_map,将两个字符串的对应字符分别存储为key 和 value
(2)查找是否存在key相同或者value相同的情况
class Solution {
public:
bool isIsomorphic(string s, string t) {
if(s.length()!=t.length()) return false;
unordered_map<char,char> sp;
for(int i=0;i<s.length();i++) {
if(sp.find(s[i])==sp.end()) {
if(find_value(sp,t[i])) return false;
else sp[s[i]]=t[i];
} else if(sp[s[i]]!=t[i]) return false;
}
return true;
}
bool find_value(unordered_map<char,char> &sp,const char &c) {
for (auto it=sp.begin();it!=sp.end();it++) {
if(it->second==c) return true;
}
return false;
}
};