leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0205.cpp (450B)
0 class Solution { 1 public: 2 bool isIsomorphic(string s, string t) { 3 unordered_map<char, char> um; 4 unordered_set<char> us; 5 6 for (int i = 0; i < s.size(); i++) { 7 if (!um.count(s[i])) { 8 if (us.count(t[i])) return false; 9 um[s[i]] = t[i]; 10 us.insert(t[i]); 11 } else if (um[s[i]] != t[i]) 12 return false; 13 } 14 15 return true; 16 } 17 };