点击打开链接
class Solution {
public:
bool isIsomorphic(string s, string t) {
if(s.size() != t.size()) return false;
map<char, char> s2t, t2s;
for(int i=0; i<s.size(); i++){
if(s2t.find(s[i]) == s2t.end()){
s2t.insert({s[i], t[i]});
}
else{
if(s2t[s[i]] != t[i]) return false;
}
if(t2s.find(t[i]) == t2s.end()){
t2s.insert({t[i],s[i]});
}
else{
if(t2s[t[i]] != s[i]) return false;
}
}
return true;
}
};