C++ solution beats 67.68%


  • 0
    E
    class Solution {
    public:
        bool isIsomorphic(string s, string t) {
            char m[256][256]={0};
            char q[256]={0};
            char p[256]={0};
            for(int i=0;i<s.size();i++){
                char ss=s[i];
                char tt=t[i];
                if(q[ss]==1 || p[tt]==1){
                    if(m[ss][tt]!=1){
                        return false;
                    }
                }else{
                  m[ss][tt]=1;
                  q[ss]=1;
                  p[tt]=1;
                }
            }
            return true;
        }
    };
    

Log in to reply
 

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