-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1100.cpp
More file actions
38 lines (31 loc) · 682 Bytes
/
Copy path1100.cpp
File metadata and controls
38 lines (31 loc) · 682 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
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
int numKLenSubstrNoRepeats(string S, int K) {
cnt = 0;
cntMore = 0;
int len = S.size();
for(int i = 0; i <= len-1; ++i)
{
m[S[i]]++;
if(m[S[i]] == 2)
{
cntMore++;
}
if(i == K-1 && cntMore == 0)cnt++;
if(i >= K)
{
m[S[i-K]]--;
if(m[S[i-K]] == 1)
{
cntMore--;
}
if(cntMore == 0)cnt++;
}
}
return cnt;
}
int cntMore;
int cnt;
map<char, int> m;
queue<char> q;
};