refer to Leetcode 290
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
# time O(N) space O(2K) : unique char
d1 = {}
d2 = {}
for i in range(len(s)):
if s[i] not in d1:
if t[i] not in d2:
d1[s[i]] = t[i]
d2[t[i]] = s[i]
else:
return False
else:
if d1[s[i]] != t[i]:
return False
return True