【leetcode❤python】 205. Isomorphic Strings

class Solution(object):
    def isIsomorphic(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        sdic={}
        slist=[]
        tdic={}
        tlist=[]
        
        if len(s)!=len(t):return False
        
        i=0;tag=0
        while i<len(s):
            if(sdic.has_key(s[i])):
                slist.append(sdic.get(s[i]))
            else:
                slist.append(tag)
                sdic.setdefault(s[i],tag)
                tag+=1
            i+=1
        
        i=0;tag=0
        while i<len(t):
            if tdic.has_key(t[i]):
                tlist.append(tdic.get(t[i]))
            else:
                tlist.append(tag)
                tdic.setdefault(t[i],tag)
                tag+=1
            i+=1
        
        return tlist==slist

原文地址:https://www.cnblogs.com/kwangeline/p/5997979.html