mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
Create is_isomorphic.py
This commit is contained in:
parent
bc0d591be1
commit
f2418e56c1
1 changed files with 15 additions and 0 deletions
15
arrays_and_strings/is_isomorphic.py
Normal file
15
arrays_and_strings/is_isomorphic.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue