- 同構(gòu)字符串
捕獲.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中的字符串不能修改绣溜,所以這里新建一個(gè)字符串
news += dicts[s[i]]
else:
dicts[s[i]] = c
news += c
# python中字符不能直接加一黄刚,所以我先轉(zhuǎn)換成ASIIC碼碘举,加一仔役,再轉(zhuǎn)化為字符
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