diff --git a/arrays_and_strings/is_isomorphic.py b/arrays_and_strings/is_isomorphic.py new file mode 100644 index 0000000..badd2ab --- /dev/null +++ b/arrays_and_strings/is_isomorphic.py @@ -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