Skip to content

Commit d340025

Browse files
authored
Create 2237-count-positions-on-street-with-required-brightness.js
1 parent 8d89d6d commit d340025

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number} n
3+
* @param {number[][]} lights
4+
* @param {number[]} requirement
5+
* @return {number}
6+
*/
7+
var meetRequirement = function(n, lights, requirement) {
8+
const arr = Array(n + 1).fill(0)
9+
for(const [pos, ra] of lights) {
10+
const start = Math.max(0, pos - ra)
11+
const end = Math.min(n - 1, pos + ra)
12+
arr[start]++
13+
arr[end + 1]--
14+
}
15+
for(let i = 1; i <= n; i++) {
16+
arr[i] += arr[i - 1]
17+
}
18+
19+
let res = 0
20+
for(let i = 0; i < n; i++) {
21+
if(arr[i] >= requirement[i]) res++
22+
}
23+
24+
return res
25+
};

0 commit comments

Comments
 (0)