Cpp easy solution, judge two maps by two hash tables


  • 0
    H
    class Solution {
    public:
        bool isIsomorphic(string s, string t) {
            int n = s.size();
            unordered_map<char, char> um1, um2;
            for(int i = 0; i < n; i ++) {
                um1[s[i]] = t[i];
                um2[t[i]] = s[i];
            }
            for(int i = 0; i < n; i ++) 
                if(um1[s[i]] !=  t[i] || um2[t[i]] != s[i]) return false;
    
            return true;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.