---
# System prepended metadata

title: 2237. Count Positions on Street With Required Brightness
tags: [Leetcode, Line Sweep, Medium]

---

# 2237. Count Positions on Street With Required Brightness
###### tags: `Leetcode` `Medium` `Line Sweep`
Link: https://leetcode.com/problems/count-positions-on-street-with-required-brightness/
## 思路
差分法找到每个pos被几个灯覆盖
## Code
```java=
class Solution {
    public int meetRequirement(int n, int[][] lights, int[] requirement) {
        int[] line = new int[n+1];
        for(int[] light:lights){
            int pos = light[0];
            int range = light[1];
            line[Math.max(0, pos-range)]++;
            line[Math.min(n-1, pos+range)+1]--;
        }
        for(int i=1; i<line.length; i++){
            line[i] += line[i-1];
        }
        int ans = 0;
        for(int i=0; i<requirement.length; i++){
            if(requirement[i]<=line[i]) ans++;
        }
        return ans;
    }
}
```