Skip to content

Commit 7c62772

Browse files
committed
https://leetcode.cn/problems/number-of-subarrays-with-bounded-maximum
1 parent b92ef6e commit 7c62772

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/number-of-subarrays-with-bounded-maximum
49+
4850
https://leetcode.cn/problems/maximum-number-of-balls-in-a-box
4951

5052
https://leetcode.cn/problems/nth-magical-number
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function numSubarrayBoundedMax(
2+
nums: number[],
3+
left: number,
4+
right: number
5+
): number {
6+
return count(nums, right) - count(nums, left - 1);
7+
}
8+
9+
function count(nums: number[], lower: number) {
10+
let res = 0,
11+
cur = 0;
12+
for (const x of nums) {
13+
cur = x <= lower ? cur + 1 : 0;
14+
res += cur;
15+
}
16+
return res;
17+
}
18+
export default numSubarrayBoundedMax;

0 commit comments

Comments
 (0)