From f2418e56c1e3223c35d7be75f2df10c67fadfcc9 Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-google@users.noreply.github.com> Date: Sun, 30 Jul 2023 14:13:02 -0700 Subject: [PATCH] Create is_isomorphic.py --- arrays_and_strings/is_isomorphic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 arrays_and_strings/is_isomorphic.py 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