Skip to content

205 isomorphic strings

205. Isomorphic Strings

题目: https://leetcode.com/problems/isomorphic-strings/

难度 : Easy

AC之法,用dictionary,因为限制,所以确保s 和 t 是isomorphic 同时 t 和 s 是

class Solution(object):
    def isIsomorphic(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        return self.iso(s,t) and self.iso(t,s)

    def iso(self,s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        mapx = {}
        for i in range(len(s)):
            if s[i] not in mapx:
                mapx[s[i]] = t[i]
            elif s[i] in mapx:
                if t[i] != mapx[s[i]]:
                    return False
        return True



我们一直在努力

apachecn/AiLearning

【布客】中文翻译组