Basic algorithm


  • 0
    N
    ​class Solution(object):
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            s=list(s);
            t=list(t);
            
            stock1=list('');
            iso1=list('');
            
            for c in s:
                if c in stock1:
                    iso1.append(stock1.index(c))
                else:
                    iso1.append(len(iso1))
                    stock1.append(c)
    
            stock2=list('');
            iso2=list('');
                    
            for c in t:
                if (c in stock2):
                    iso2.append(stock2.index(c))
                else:
                    iso2.append(len(iso2))
                    stock2.append(c)
                    
            return(iso1==iso2)
    

Log in to reply
 

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