Isomorphic Strings

这里的关系是双向对应的,需要有两个哈希表

class Solution(object):
    def isIsomorphic(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        posJisho = {}
        negJisho = {}

        for index, char in enumerate(s):
            if char in posJisho and posJisho[char] != t[index]:
                return False
            if t[index] in negJisho and negJisho[t[index]] != char:
                return False
            posJisho[char] = t[index]
            negJisho[t[index]] = char

        return True

results matching ""

    No results matching ""