205. 同构字符串

  1. 同构字符串
捕获.PNG

https://leetcode-cn.com/problems/isomorphic-strings/

class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        dicts = {}
        dictt = {}
        c = 'a'
        c1 = 'a'
        news = ''
        newt = ''
        length = len(s)
        for i in range(length):
            if s[i] in dicts:
                # python中的字符串不能修改,所以这里新建一个字符串
                news += dicts[s[i]]
            else:
                dicts[s[i]] = c
                news += c
                # python中字符不能直接加一,所以我先转换成ASIIC码,加一,再转化为字符
                c = chr(ord(c)+1)
            if t[i] in dictt:
                newt += dictt[t[i]]
            else:
                dictt[t[i]] = c1
                newt += c1
                c1 = chr(ord(c1)+1)
        return newt==news

你可能感兴趣的:(205. 同构字符串)