解题思路:
首先,把这两个列表,变成字典的形式,肯定都是一一对应的值,利用哈希表,将两个列表变成一个字典,一一对应在这里插入代码片
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
hashmap={}
for i,j in zip(s,t):
if i in hashmap and hashmap[i]!=j:#有两种情况,如果是同构,构成的字典,肯定是一一对应的
return False
elif i not in hashmap and j in hashmap.values():#如果i不在键的话,也肯定是错的
return False
hashmap[i]=j #都满足的话,就键值相等喽
return True