fast python solution


  • 0
    Z
    class Solution(object):
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            hash = {}
            for i in xrange(len(s)):
                try:
                    if hash[s[i]] == t[i]:
                        continue
                    else:
                        return False
                except:
                    if t[i] in hash.itervalues():
                        return False
                    hash[s[i]] = t[i]
            return True
    

Log in to reply
 

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