Sunday, November 5, 2017

205. Isomorphic Strings

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

No comments:

Post a Comment