Create is_isomorphic.py

This commit is contained in:
bt3gl 2023-07-30 14:13:02 -07:00 committed by GitHub
parent bc0d591be1
commit f2418e56c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,15 @@
def is_isomorphic(s: str, t: str) -> bool:
map_s_to_t = {}
map_t_to_s = {}
for ss, tt in zip(s, t):
if (ss not in map_s_to_t) and (tt not in map_t_to_s):
map_s_to_t[ss] = tt
map_t_to_s[tt] = ss
elif (map_s_to_t.get(ss) != tt) or (map_t_to_s.get(tt) != ss):
return False
return True