Isomorphic Strings
要点:一道简单题,要点就是map不是bijection的,所以要用两个map来表示bijection
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
smap = {}
tmap = {}
if len(s)!=len(t): return False
for i in range(len(s)):
if s[i] not in smap:
smap[s[i]]=t[i]
elif smap[s[i]]!=t[i]:
return False
if t[i] not in tmap:
tmap[t[i]]=s[i]
elif tmap[t[i]]!=s[i]:
return False
return True