-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path205_IsomorphicStrings.py
More file actions
47 lines (42 loc) · 1.04 KB
/
205_IsomorphicStrings.py
File metadata and controls
47 lines (42 loc) · 1.04 KB
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
46
47
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
# check length
n = len(s)
m = len(t)
if n != m:
return False
# dic check
dic = {}
for i in range(n):
if s[i] in dic:
if dic[s[i]] != t[i]:
return False
elif t[i] in dic.values():
return False
else:
dic[s[i]] = t[i]
return True
def main():
# Input:
s = "egg"
t = "add"
# Output: true
print(Solution().isIsomorphic(s, t))
print('--------------------------------------------------------')
# Explanation:
# input
s = "foo"
t = "bar"
# Output: false
# Explanation:
print(Solution().isIsomorphic(s, t))
print('--------------------------------------------------------')
# Explanation:
# input
s = "paper"
t = "title"
# Output: true
# Explanation:
print(Solution().isIsomorphic(s, t))
if __name__ == '__main__':
main()