File tree Expand file tree Collapse file tree 1 file changed +19
-20
lines changed
May-LeetCoding-Challenge/17-Find-All-Anagrams-In-A-String Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Original file line number Diff line number Diff line change 1
1
class Solution :
2
- def findAnagrams (self , s : str , p : str ) -> List [int ]:
3
- sl = len (s )
4
- droite ,taille = len (p ),len (p )
5
- if (sl < droite ):
2
+ def findAnagrams (self , s : str , p : str ) -> List [int ]:
3
+ sl = len (s )
4
+ droite , taille = len (p ), len (p )
5
+ if (sl < droite ):
6
6
return []
7
7
res = []
8
8
window = dict ()
9
9
need = dict ()
10
- for c in p :
10
+ for c in p :
11
11
need [c ] = need .get (c , 0 ) + 1
12
12
tmp = s [0 ]
13
13
gauche = 0
14
- droite = gauche + taille
14
+ droite = gauche + taille
15
15
for c in s [:droite ]:
16
- window [c ] = window .get (c ,0 ) + 1
17
- if (window == need ):
16
+ window [c ] = window .get (c , 0 ) + 1
17
+ if (window == need ):
18
18
res .append (0 )
19
- while (droite < sl ):
19
+ while (droite < sl ):
20
20
debut = s [gauche ]
21
21
value = window .get (debut )
22
- if (value <= 1 ):
22
+ if (value <= 1 ):
23
23
del window [debut ]
24
24
else :
25
- window [debut ]-= 1
25
+ window [debut ] -= 1
26
26
tmp = s [droite ]
27
- #print("tmp = ",tmp)
28
- if (tmp not in need ):
27
+ if (tmp not in need ):
29
28
window .clear ()
30
- gauche += 1
31
- droite = gauche + taille
29
+ gauche += 1
30
+ droite = gauche + taille
32
31
for c in s [gauche :droite ]:
33
- window [c ]= window .get (c ,0 ) + 1
32
+ window [c ] = window .get (c , 0 ) + 1
34
33
else :
35
- window [tmp ] = window .get (tmp ,0 ) + 1
36
- gauche += 1
37
- droite = gauche + taille
38
- if (window == need ):
34
+ window [tmp ] = window .get (tmp , 0 ) + 1
35
+ gauche += 1
36
+ droite = gauche + taille
37
+ if (window == need ):
39
38
res .append (gauche )
40
39
return res
You can’t perform that action at this time.
0 commit comments