class Solution:
def helper(self, s: str, t: str) -> bool:
mp = {}
for i in range(len(s)):
if (s[i] in mp) and (mp[s[i]] != t[i]):
return False
mp[s[i]] = t[i]
return True
def isIsomorphic(self, s: str, t: str) -> bool:
return self.helper(s, t) and self.helper(t, s)Where is the length of the input string and is the number of unique characters in the strings.
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
mapST, mapTS = {}, {}
for i in range(len(s)):
c1, c2 = s[i], t[i]
if ((c1 in mapST and mapST[c1] != c2) or
(c2 in mapTS and mapTS[c2] != c1)):
return False
mapST[c1] = c2
mapTS[c2] = c1
return TrueWhere is the length of the input string and is the number of unique characters in the strings.