Best python solution, Beats 100% of python submissions


  • 0
    S
    class Solution(object):
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            
            pattern_dict = {}
            s_len = len(s)
            for i in range(s_len):
                if s[i] not in pattern_dict:
                    if t[i] in pattern_dict.values():
                        return False
                    pattern_dict[s[i]] = t[i]
                elif pattern_dict[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.