Simple Python solution


  • 0
    A
    class Solution:
        def isIsomorphic(self, s, t):
            """
            :type s: str
            :type t: str
            :rtype: bool
            """
            mapping = {}
            if len(s) == len(t):
                for i, j in zip(s, t):
                    if i in mapping:
                        i = mapping[i]
                        if i != j:
                            return False
                    else:
                        if j in mapping.values():
                            return False
                        mapping[i] = j
                return True
            return False
            
    

Log in to reply
 

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