Skip to content

Commit 46d54df

Browse files
authored
Create Isomorphic-Strings.py
1 parent 25d4d22 commit 46d54df

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Leetcode/Isomorphic-Strings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def isIsomorphic(self, s: str, t: str) -> bool:
3+
if len(s) == 0:
4+
return True
5+
6+
replaced_s = [""] * len(s)
7+
letter_table = {}
8+
char_set = set()
9+
for index in range(0, len(s)):
10+
digit = s[index]
11+
if not digit in letter_table:
12+
letter_table[digit] = t[index]
13+
if t[index] not in char_set:
14+
char_set.add(t[index])
15+
else:
16+
return False
17+
replaced_s[index] = letter_table[digit]
18+
replaced_s = "".join(replaced_s)
19+
return replaced_s == t

0 commit comments

Comments
 (0)