Skip to content

Commit 34e2104

Browse files
authored
Update Solution.cpp
1 parent 16b6a31 commit 34e2104

File tree

1 file changed

+11
-5
lines changed
  • solution/2400-2499/2444.Count Subarrays With Fixed Bounds

1 file changed

+11
-5
lines changed

solution/2400-2499/2444.Count Subarrays With Fixed Bounds/Solution.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ class Solution {
33
long long countSubarrays(vector<int>& nums, int minK, int maxK) {
44
long long ans = 0;
55
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;
6+
for (int i = 0; i < static_cast<int>(nums.size()); ++i) {
7+
if (nums[i] < minK || nums[i] > maxK) {
8+
k = i;
9+
}
10+
if (nums[i] == minK) {
11+
j1 = i;
12+
}
13+
if (nums[i] == maxK) {
14+
j2 = i;
15+
}
1016
ans += max(0, min(j1, j2) - k);
1117
}
1218
return ans;
1319
}
14-
};
20+
};

0 commit comments

Comments
 (0)