205. 同构字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char, char>M;
for(int i=0;i<s.size();i++){
char ss = s[i], tt = t[i];
if(M.find(ss)==M.end()){
if(find_if(M.begin(),M.end(),[&](const map<char, char>::iterator&it){return it->second==tt;})!=M.end()){
return false;
}else{
M[ss]=tt;
}
}else{
if(M[ss]!=tt){
return false;
}
}
}
return true;
}
};