mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
19 lines
351 B
Go
19 lines
351 B
Go
package leetcode
|
|
|
|
func numSubarrayBoundedMax(nums []int, left int, right int) int {
|
|
return getAnswerPerBound(nums, right) - getAnswerPerBound(nums, left-1)
|
|
}
|
|
|
|
func getAnswerPerBound(nums []int, bound int) int {
|
|
res, count := 0, 0
|
|
for _, num := range nums {
|
|
if num <= bound {
|
|
count++
|
|
} else {
|
|
count = 0
|
|
}
|
|
res += count
|
|
}
|
|
return res
|
|
}
|