-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1100.py
24 lines (22 loc) · 841 Bytes
/
1100.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
__________________________________________________________________________________________________
class Solution:
def numKLenSubstrNoRepeats(self, S: str, K: int) -> int:
i, j = 0, K-1,
cnt = collections.Counter(S[i:j+1])
print(cnt)
if K > len(S):
return 0
res = 0
for _ in range(len(S) - K+1):
if len(cnt) == K:
res += 1
if j + 1 < len(S):
cnt[S[j+1]] += 1
cnt[S[i]] -= 1
if cnt[S[i]] == 0:
del cnt[S[i]]
j += 1
i += 1
return res
__________________________________________________________________________________________________
__________________________________________________________________________________________________