File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
number-of-subarrays-with-bounded-maximum Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/number-of-subarrays-with-bounded-maximum
49
+
48
50
https://leetcode.cn/problems/maximum-number-of-balls-in-a-box
49
51
50
52
https://leetcode.cn/problems/nth-magical-number
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments