LC 205. Isomorphic Strings

Nilanjan Deb · April 6, 2020

This is my CPP solution.

class Solution {
public:
    bool isIsomorphic(string s, string t) {
        vector<int> s_map(128,0);
        vector<int> t_map(128,0);
        int n = s.size(), m = t.size();
        if(n != m)
            return false;
        for(int i=0;i<n;i++){
            if(s_map[s[i]]!=t_map[t[i]])
                return false;
            else if(!(s_map[s[i]] || t_map[t[i]])){
                s_map[s[i]] = i+1;
                t_map[t[i]] = i+1;
            }
        }
        return true;
    }
};


Dicussion Forum