Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created April 9, 2018 15:06
Show Gist options
  • Save s4553711/8d7b0356f555d3dad01fc810a0e7d060 to your computer and use it in GitHub Desktop.
Save s4553711/8d7b0356f555d3dad01fc810a0e7d060 to your computer and use it in GitHub Desktop.
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char, char> m1;
map<char, char> m2;
bool flag = true;
for(int i = 0; i < s.size(); i++) {
if (m1.find(s[i]) == m1.end() && m2.find(t[i]) == m2.end()) {
m1[s[i]] = t[i];
m2[t[i]] = s[i];
} else if (m1.find(s[i]) != m1.end() && m2.find(t[i]) != m2.end()) {
if (m1[s[i]] != t[i] || m2[t[i]] != s[i]) {
flag = false;
break;
}
} else {
flag = false;
break;
}
}
return flag;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment