Isomorphic Strings LeetCode solution in C++

1
class Solution {
2
public:
3
bool isIsomorphic(string s, string t) {
4
if (s.size() != t.size()) return false;
5
unordered_map<char, char> mp;
6
for (int i = 0; i < s.size(); i++) {
7
if (mp.find(s[i]) == mp.end()) {
8
for (auto it : mp) {
9
if (it.second == t[i]) return false;
10
}
11
mp[s[i]] = t[i];
12
} else {
13
if (mp[s[i]] != t[i]) return false;
14
}
15
}
16
return true;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0