We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 16b6a31 commit 34e2104Copy full SHA for 34e2104
solution/2400-2499/2444.Count Subarrays With Fixed Bounds/Solution.cpp
@@ -3,12 +3,18 @@ class Solution {
3
long long countSubarrays(vector<int>& nums, int minK, int maxK) {
4
long long ans = 0;
5
int j1 = -1, j2 = -1, k = -1;
6
- for (int i = 0; i < nums.size(); ++i) {
7
- if (nums[i] < minK || nums[i] > maxK) k = i;
8
- if (nums[i] == minK) j1 = i;
9
- if (nums[i] == maxK) j2 = i;
+ for (int i = 0; i < static_cast<int>(nums.size()); ++i) {
+ if (nums[i] < minK || nums[i] > maxK) {
+ k = i;
+ }
10
+ if (nums[i] == minK) {
11
+ j1 = i;
12
13
+ if (nums[i] == maxK) {
14
+ j2 = i;
15
16
ans += max(0, min(j1, j2) - k);
17
}
18
return ans;
19
-};
20
+};
0 commit comments