O(n) time O(128) space
normalize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public: bool isIsomorphic(string s, string t) { int ms[128] = {0}, mt[128] = {0}; int n = s.length(); for (int i = 0; i < n; ++i) { if (ms[s[i]] == 0) { ms[s[i]] = i + 1; } if (mt[t[i]] == 0) { mt[t[i]] = i + 1; } if (ms[s[i]] != mt[t[i]]) return false; } return true; } };
|