-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathiso.py
More file actions
28 lines (25 loc) · 852 Bytes
/
iso.py
File metadata and controls
28 lines (25 loc) · 852 Bytes
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
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
# Initial logic - get count of respective character for each of the strings, sort the counts into a list and compare both such list to verify if they are equal
# Every index also is taken into account with the count
# Second logic - second logic
sc = {}
tc = {}
n = len(s)
# Same length strings
for i in range(n):
if s[i] not in sc:
sc[s[i]] = []
sc[s[i]].append(i)
if t[i] not in tc:
tc[t[i]] = []
tc[t[i]].append(i)
if sorted(tc.values()) == sorted(sc.values()):
return True
else:
return False