From 10cedc3615d10af8e6a871284ea612f9505173fb Mon Sep 17 00:00:00 2001 From: Sai Sahith <91070868+sai-sahith7@users.noreply.github.com> Date: Mon, 30 May 2022 22:04:04 +0530 Subject: [PATCH 1/2] day1 --- POD/Week2-Strings/day1.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 POD/Week2-Strings/day1.py diff --git a/POD/Week2-Strings/day1.py b/POD/Week2-Strings/day1.py new file mode 100644 index 0000000..2fe8e14 --- /dev/null +++ b/POD/Week2-Strings/day1.py @@ -0,0 +1,15 @@ +class Solution: + def isIsomorphic(self, s: str, t: str) -> bool: + d = dict() + flag = True + l = len(t) + for i in range(l): + if s[i] not in d.keys(): + if t[i] in d.values(): + flag = False + break + d[s[i]] = t[i] + elif d[s[i]] != t[i]: + flag = False + break + return flag From 5205ca2e29008ced673c9949d9876d141dd1859d Mon Sep 17 00:00:00 2001 From: Sai Sahith <91070868+sai-sahith7@users.noreply.github.com> Date: Tue, 31 May 2022 20:35:53 +0530 Subject: [PATCH 2/2] commit day-1 upated comments --- POD/Week2-Strings/day1.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/POD/Week2-Strings/day1.py b/POD/Week2-Strings/day1.py index 2fe8e14..f04debe 100644 --- a/POD/Week2-Strings/day1.py +++ b/POD/Week2-Strings/day1.py @@ -1,15 +1,15 @@ class Solution: def isIsomorphic(self, s: str, t: str) -> bool: - d = dict() + d = dict() #dictionary to allot characters of s as keys and characters of t as values flag = True l = len(t) for i in range(l): - if s[i] not in d.keys(): - if t[i] in d.values(): + if s[i] not in d.keys(): #checking if the character of s has already been allotted to a character of t + if t[i] in d.values(): #checking if character of t has been allotted to different character of s flag = False break - d[s[i]] = t[i] - elif d[s[i]] != t[i]: + d[s[i]] = t[i] #alloting a character of s to character of t + elif d[s[i]] != t[i]: #checking if character of t is not equal to previously allotted character in dictionary flag = False break return flag