Skip to content

Commit 6108f3f

Browse files
authored
Create Number of Subarrays with Bounded Maximum.java
1 parent cc86fef commit 6108f3f

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 int numSubarrayBoundedMax(int[] nums, int left, int right) {
3+
return countHelper(nums, right) - countHelper(nums, left - 1);
4+
}
5+
6+
private int countHelper(int[] nums, int bound) {
7+
int count = 0;
8+
int curr = 0;
9+
for (int num : nums) {
10+
curr = num <= bound ? curr + 1 : 0;
11+
count += curr;
12+
}
13+
return count;
14+
}
15+
}

0 commit comments

Comments
 (0)