6ms C++ solution


  • 0
    D
    class Solution {
    public:
        bool isIsomorphic(string s, string t) {
            vector<int> ss(200,0),tt(200,0),pos(200,0);
            for(int i=0;i<s.size();i++){
                if(ss[s[i]-'A'+50]==0 && tt[t[i]-'A'+50]==0){
                    ++ss[s[i]-'A'+50];
                    ++tt[t[i]-'A'+50];
                    pos[s[i]]=s[i]-t[i];
                }
                if(s[i]-t[i]!=pos[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.