|
| 1 | +# [2021. Brightest Position on Street](https://leetcode-cn.com/problems/brightest-position-on-street) |
| 2 | + |
| 3 | +[English Version](/solution/2000-2099/2021.Brightest%20Position%20on%20Street/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array <code>lights</code>. 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>[position<sub>i</sub> - range<sub>i</sub>, 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 lamp that light up the position <code>p</code>.</p> |
| 12 | + |
| 13 | +<p>Given <code>lights</code>, return <em>the <strong>brightest</strong> position on the</em><em> street. If there are multiple brightest positions, return the <strong>smallest</strong> one.</em></p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong>Example 1:</strong></p> |
| 17 | +<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2000-2099/2021.Brightest%20Position%20on%20Street/images/image-20210928155140-1.png" style="width: 700px; height: 165px;" /> |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> lights = [[-3,2],[1,2],[3,3]] |
| 20 | +<strong>Output:</strong> -1 |
| 21 | +<strong>Explanation:</strong> |
| 22 | +The first street lamp lights up the area from [(-3) - 2, (-3) + 2] = [-5, -1]. |
| 23 | +The second street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3]. |
| 24 | +The third street lamp lights up the area from [3 - 3, 3 + 3] = [0, 6]. |
| 25 | + |
| 26 | +Position -1 has a brightness of 2, illuminated by the first and second street light. |
| 27 | +Positions 0, 1, 2, and 3 have a brightness of 2, illuminated by the second and third street light. |
| 28 | +Out of all these positions, -1 is the smallest, so return it. |
| 29 | +</pre> |
| 30 | + |
| 31 | +<p><strong>Example 2:</strong></p> |
| 32 | + |
| 33 | +<pre> |
| 34 | +<strong>Input:</strong> lights = [[1,0],[0,1]] |
| 35 | +<strong>Output:</strong> 1 |
| 36 | +<strong>Explanation:</strong> |
| 37 | +The first street lamp lights up the area from [1 - 0, 1 + 0] = [1, 1]. |
| 38 | +The second street lamp lights up the area from [0 - 1, 0 + 1] = [-1, 1]. |
| 39 | + |
| 40 | +Position 1 has a brightness of 2, illuminated by the first and second street light. |
| 41 | +Return 1 because it is the brightest position on the street. |
| 42 | +</pre> |
| 43 | + |
| 44 | +<p><strong>Example 3:</strong></p> |
| 45 | + |
| 46 | +<pre> |
| 47 | +<strong>Input:</strong> lights = [[1,2]] |
| 48 | +<strong>Output:</strong> -1 |
| 49 | +<strong>Explanation:</strong> |
| 50 | +The first street lamp lights up the area from [1 - 2, 1 + 2] = [-1, 3]. |
| 51 | + |
| 52 | +Positions -1, 0, 1, 2, and 3 have a brightness of 1, illuminated by the first street light. |
| 53 | +Out of all these positions, -1 is the smallest, so return it. |
| 54 | +</pre> |
| 55 | + |
| 56 | +<p> </p> |
| 57 | +<p><strong>Constraints:</strong></p> |
| 58 | + |
| 59 | +<ul> |
| 60 | + <li><code>1 <= lights.length <= 10<sup>5</sup></code></li> |
| 61 | + <li><code>lights[i].length == 2</code></li> |
| 62 | + <li><code>-10<sup>8</sup> <= position<sub>i</sub> <= 10<sup>8</sup></code></li> |
| 63 | + <li><code>0 <= range<sub>i</sub> <= 10<sup>8</sup></code></li> |
| 64 | +</ul> |
| 65 | + |
| 66 | + |
| 67 | +## 解法 |
| 68 | + |
| 69 | +<!-- 这里可写通用的实现逻辑 --> |
| 70 | + |
| 71 | +<!-- tabs:start --> |
| 72 | + |
| 73 | +### **Python3** |
| 74 | + |
| 75 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 76 | + |
| 77 | +```python |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +### **Java** |
| 82 | + |
| 83 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 84 | + |
| 85 | +```java |
| 86 | + |
| 87 | +``` |
| 88 | + |
| 89 | +### **...** |
| 90 | + |
| 91 | +``` |
| 92 | +
|
| 93 | +``` |
| 94 | + |
| 95 | +<!-- tabs:end --> |
0 commit comments