-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path1153.py
27 lines (23 loc) · 929 Bytes
/
1153.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
__________________________________________________________________________________________________
class Solution:
def canConvert(self, str1: str, str2: str) -> bool:
s1 = dict()
for i, ch in enumerate(str1):
if ch not in s1:
s1[ch] = list()
s1[ch].append(i)
s2 = dict()
for i, ch in enumerate(str2):
if ch not in s2:
s2[ch] = list()
s2[ch].append(i)
if len(s1) == len(s2) == 26 and str1 != str2:
return False
for k, v in s1.items():
pivot = str2[v[0]]
for pos in v:
if str2[pos] != pivot:
return False
return True
__________________________________________________________________________________________________
__________________________________________________________________________________________________