LeetCode - The World's Leading Online Programming Learning Platform
python
from collections import defaultdict
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
mydict1={}
mydict0={}
for i in range(len(s)):
c1=(s[i] not in mydict1)
c0=(t[i] not in mydict0)
if c1 and c0:
mydict1[s[i]]=t[i]
mydict0[t[i]]=s[i]
elif (not c0) and (not c1):
if mydict1[s[i]]!=t[i] or mydict0[t[i]]!=s[i]:
return False
else: return False
return True
双向map