Skip to content

Commit d69b86b

Browse files
committed
Runtime: 196 ms (Top 75.30%) | Memory: 70.9 MB (Top 52.97%)
1 parent 6201ef8 commit d69b86b

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
// Runtime: 196 ms (Top 75.30%) | Memory: 70.9 MB (Top 52.97%)
12
class Solution {
23
public:
3-
vector<int> nums;
4-
int solve(int k){
5-
int low = 0, high = 0, cnt = 0, res = 0;
4+
vector<int> nums;
5+
int solve(int k){
6+
int low = 0, high = 0, cnt = 0, res = 0;
67

7-
while(high < nums.size()){
8-
if(nums[high] & 1){
9-
cnt++;
8+
while(high < nums.size()){
9+
if(nums[high] & 1){
10+
cnt++;
1011

11-
while(cnt > k){
12-
if(nums[low] & 1) cnt--;
13-
low++;
14-
}
15-
}
16-
high++;
17-
res += high - low;
18-
}
12+
while(cnt > k){
13+
if(nums[low] & 1) cnt--;
14+
low++;
15+
}
16+
}
17+
high++;
18+
res += high - low;
19+
}
1920

20-
return res;
21-
}
22-
int numberOfSubarrays(vector<int>& nums, int k) {
23-
this -> nums = nums;
24-
return solve(k) - solve(k - 1);
25-
}
21+
return res;
22+
}
23+
int numberOfSubarrays(vector<int>& nums, int k) {
24+
this -> nums = nums;
25+
return solve(k) - solve(k - 1);
26+
}
2627
};

0 commit comments

Comments
 (0)