|
| 1 | +# [2237. Count Positions on Street With Required Brightness](https://leetcode-cn.com/problems/count-positions-on-street-with-required-brightness) |
| 2 | + |
| 3 | +[English Version](/solution/2200-2299/2237.Count%20Positions%20on%20Street%20With%20Required%20Brightness/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>You are given an integer <code>n</code>. A perfectly straight street is represented by a number line ranging from <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>lights</code> representing the street lamp(s) on the street. Each <code>lights[i] = [position<sub>i</sub>, range<sub>i</sub>]</code> indicates that there is a street lamp at position <code>position<sub>i</sub></code> that lights up the area from <code>[max(0, position<sub>i</sub> - range<sub>i</sub>), min(n - 1, position<sub>i</sub> + range<sub>i</sub>)]</code> (<strong>inclusive</strong>).</p> |
| 10 | + |
| 11 | +<p>The <strong>brightness</strong> of a position <code>p</code> is defined as the number of street lamps that light up the position <code>p</code>. You are given a <strong>0-indexed</strong> integer array <code>requirement</code> of size <code>n</code> where <code>requirement[i]</code> is the minimum <strong>brightness</strong> of the <code>i<sup>th</sup></code> position on the street.</p> |
| 12 | + |
| 13 | +<p>Return <em>the number of positions </em><code>i</code><em> on the street between </em><code>0</code><em> and </em><code>n - 1</code><em> that have a <strong>brightness</strong> </em><em>of <strong>at least</strong> </em><code>requirement[i]</code><em>.</em></p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong>Example 1:</strong></p> |
| 17 | +<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2237.Count%20Positions%20on%20Street%20With%20Required%20Brightness/images/screenshot-2022-04-11-at-22-24-43-diagramdrawio-diagramsnet.png" style="height: 150px; width: 579px;" /> |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1] |
| 20 | +<strong>Output:</strong> 4 |
| 21 | +<strong>Explanation:</strong> |
| 22 | +- The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 1] (inclusive). |
| 23 | +- The second street lamp lights up the area from [max(0, 2 - 1), min(n - 1, 2 + 1)] = [1, 3] (inclusive). |
| 24 | +- The third street lamp lights up the area from [max(0, 3 - 2), min(n - 1, 3 + 2)] = [1, 4] (inclusive). |
| 25 | + |
| 26 | +- Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is greater than requirement[0]. |
| 27 | +- Position 1 is covered by the first, second, and third street lamps. It is covered by 3 street lamps which is greater than requirement[1]. |
| 28 | +- Position 2 is covered by the second and third street lamps. It is covered by 2 street lamps which is greater than requirement[2]. |
| 29 | +- Position 3 is covered by the second and third street lamps. It is covered by 2 street lamps which is less than requirement[3]. |
| 30 | +- Position 4 is covered by the third street lamp. It is covered by 1 street lamp which is equal to requirement[4]. |
| 31 | + |
| 32 | +Positions 0, 1, 2, and 4 meet the requirement so we return 4. |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p><strong>Example 2:</strong></p> |
| 36 | + |
| 37 | +<pre> |
| 38 | +<strong>Input:</strong> n = 1, lights = [[0,1]], requirement = [2] |
| 39 | +<strong>Output:</strong> 0 |
| 40 | +<strong>Explanation:</strong> |
| 41 | +- The first street lamp lights up the area from [max(0, 0 - 1), min(n - 1, 0 + 1)] = [0, 0] (inclusive). |
| 42 | +- Position 0 is covered by the first street lamp. It is covered by 1 street lamp which is less than requirement[0]. |
| 43 | +- We return 0 because no position meets their brightness requirement. |
| 44 | +</pre> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | +<p><strong>Constraints:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li><code>1 <= n <= 10<sup>5</sup></code></li> |
| 51 | + <li><code>1 <= lights.length <= 10<sup>5</sup></code></li> |
| 52 | + <li><code>0 <= position<sub>i</sub> < n</code></li> |
| 53 | + <li><code>0 <= range<sub>i</sub> <= 10<sup>5</sup></code></li> |
| 54 | + <li><code>requirement.length == n</code></li> |
| 55 | + <li><code>0 <= requirement[i] <= 10<sup>5</sup></code></li> |
| 56 | +</ul> |
| 57 | + |
| 58 | + |
| 59 | +## 解法 |
| 60 | + |
| 61 | +<!-- 这里可写通用的实现逻辑 --> |
| 62 | + |
| 63 | +<!-- tabs:start --> |
| 64 | + |
| 65 | +### **Python3** |
| 66 | + |
| 67 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 68 | + |
| 69 | +```python |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +### **Java** |
| 74 | + |
| 75 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 76 | + |
| 77 | +```java |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +### **TypeScript** |
| 82 | + |
| 83 | +```ts |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +### **...** |
| 88 | + |
| 89 | +``` |
| 90 | +
|
| 91 | +``` |
| 92 | + |
| 93 | +<!-- tabs:end --> |
0 commit comments