leetcode - 205. 同构字符串
题目:
代码:
#include <iostream>
#include <map>
using namespace std;
bool isIsomorphic(string s, string t) {
unordered_map<char,char> visited;
unordered_map<char,char> f;
int n = s.size();
for(int i = 0; i < n; i++){
char c1 = s[i];
char c2 = t[i];
if(visited.count(c1)){
if(visited[c1] != c2){
return false;
}
}else{
visited[c1] = c2;
}
if(f.count(c2)){
if(f[c2] != c1){
return false;
}
}else{
f[c2] = c1;
}
}
return true;
}
int main(){
bool res;
string s, t;
cin>>s>>t;
res = isIsomorphic(s, t);
if(res){
cout<<"true";
}else{
cout<<"false";
}
return 0;
}