-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path205.py
45 lines (31 loc) · 1.03 KB
/
205.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'''205. Isomorphic Strings
Created on 2024-12-18 13:19:49
2024-12-18 13:38:54
@author: MilkTea_shih
'''
#%% Packages
#%% Variable
#%% Functions
class Solution_reference:
def isIsomorphic(self, s: str, t: str) -> bool:
zipped_set: set[tuple[str, str]] = set(zip(s, t))
return len(zipped_set) == len(set(s)) == len(set(t))
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
mapping_table: dict[str, str] = {}
seen_letter: set[str] = set()
for index in range(len(s)):
if s[index] in mapping_table:
if mapping_table[s[index]] != t[index]:
return False #wrong mapping from `s[index] -> t[index]`
else:
if t[index] in seen_letter:
return False #`t[index]` not mapping to same `s[index]`
mapping_table[s[index]] = t[index]
seen_letter.add(t[index])
return True
#%% Main Function
#%% Main
if __name__ == '__main__':
pass
#%%