C++ solution


  • 0
    P

    class Solution {
    public:
    bool isIsomorphic(string s, string t) {

        if(s.length()!=t.length())
            return false;
            
        int charStore[256] = {};
        int result[256] = {};
        
        
        for(int  i = 0 ; i < s.length(); i++ )
        {
            
            if(charStore[s[i]]==0 )
            {
                 if(result[t[i]] !=0 && charStore[s[i]] != t[i])
                 return false;
                 
                 
                 
                charStore[s[i]] = t[i];
                result[t[i]] = s[i];
            }else
            {
                if(charStore[s[i]] !=t[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.