leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0205.cpp (450B)


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