Skip to content

Commit a2ff644

Browse files
committed
Time: 8 ms (54.6%), Space: 59.9 MB (92.58%) - LeetHub
1 parent 045ea0e commit a2ff644

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public long countSubarrays(int[] nums, int minK, int maxK) {
3+
long res = 0;
4+
int bad = -1, left = -1, right = -1;
5+
6+
for (int i = 0; i < nums.length; i++) {
7+
if (nums[i] < minK || nums[i] > maxK) bad = i;
8+
if (nums[i] == minK) left = i;
9+
if (nums[i] == maxK) right = i;
10+
res += Math.max(0, Math.min(left, right) - bad);
11+
}
12+
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)