-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc-100165.py
More file actions
27 lines (22 loc) · 803 Bytes
/
lc-100165.py
File metadata and controls
27 lines (22 loc) · 803 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
class Solution:
def beautifulIndices(self, s: str, a: str, b: str, k: int):
one = len(s) - len(a) + 1
two = len(s) - len(b) + 1
potential_a = []
potential_b = []
beautiful = set()
for i in range(0, one):
if s[i: len(a)+i] == a:
potential_a.append( i )
for j in range(0, two):
if s[j: len(b)+j] == b:
potential_b.append( j )
# print(potential_a)
# print(potential_b)
for _a in potential_a:
for _b in potential_b:
if abs(_b - _a) <= k:
beautiful.add(_a)
return sorted(list(beautiful))
soln = Solution()
print(soln.beautifulIndices("isawsquirrelnearmysquirrelhouseohmy", "my", "squirrel", 15))