LeetCode 205. 同构字符串
哈希表,还是用两个哈希表构建双射关系比较合适
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
length = len(s)
d = {}
for i in range(length):
if s[i] not in d:
d[s[i]] = t[i]
else:
if d[s[i]] != t[i]:
return False
return len(set(d.keys())) == len(set(d.values()))