My python 100% run time solution


  • 0
    A
    class Solution(object):
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
    
            d = {}
            value_set = set()
            
            for index, letter in enumerate(s):
                try:
                    if d[letter] != t[index]:
                        return False
                except KeyError:    
                    d[letter] = t[index]
                    if d[letter] in value_set:
                        return False
                    value_set.add(d[letter])
    
            return True
    

Log in to reply
 

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