205_IsomorphicStrings - a920604a/leetcode GitHub Wiki
class Solution {
public:
bool isIsomorphic(string s, string t) {
unordered_map<char, int> mpa, mpb;
int n = s.size(), m=t.size();
if(m!=n) return false;
for(int i=0;i<n;++i){
if(mpa[s[i]]!=mpb[t[i]]) return false;
mpa[s[i]] = i+1;
mpb[t[i]] = i+1;
}
return true;
}
};
- time complexity
O(nlogn)
- space complexity
O(n)