8ms C++ short code without map, thanks to ASCII


  • 4
    J
    bool isIsomorphic(string a, string b) {
        if(a.size()!=b.size()) return false;
        vector<char> aTob(128, NULL);
        vector<char> bToa(128, NULL);
        for (int i=0; i<a.size(); i++) {
            if(!aTob[a[i]] && !bToa[b[i]]) {
                aTob[a[i]] = b[i];
                bToa[b[i]] = a[i];
            }
             else if(aTob[a[i]]!=b[i] || bToa[b[i]]!=a[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.