|
| 1 | +# [2345. Finding the Number of Visible Mountains](https://leetcode.cn/problems/finding-the-number-of-visible-mountains) |
| 2 | + |
| 3 | +[English Version](/solution/2300-2399/2345.Finding%20the%20Number%20of%20Visible%20Mountains/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>You are given a <strong>0-indexed</strong> 2D integer array <code>peaks</code> where <code>peaks[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> states that mountain <code>i</code> has a peak at coordinates <code>(x<sub>i</sub>, y<sub>i</sub>)</code>. A mountain can be described as a right-angled isosceles triangle, with its base along the <code>x</code>-axis and a right angle at its peak. More formally, the <strong>gradients</strong> of ascending and descending the mountain are <code>1</code> and <code>-1</code> respectively.</p> |
| 10 | + |
| 11 | +<p>A mountain is considered <strong>visible</strong> if its peak does not lie within another mountain (including the border of other mountains).</p> |
| 12 | + |
| 13 | +<p>Return <em>the number of visible mountains</em>.</p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong>Example 1:</strong></p> |
| 17 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2300-2399/2345.Finding%20the%20Number%20of%20Visible%20Mountains/images/ex1.png" style="width: 402px; height: 210px;" /> |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> peaks = [[2,2],[6,3],[5,4]] |
| 20 | +<strong>Output:</strong> 2 |
| 21 | +<strong>Explanation:</strong> The diagram above shows the mountains. |
| 22 | +- Mountain 0 is visible since its peak does not lie within another mountain or its sides. |
| 23 | +- Mountain 1 is not visible since its peak lies within the side of mountain 2. |
| 24 | +- Mountain 2 is visible since its peak does not lie within another mountain or its sides. |
| 25 | +There are 2 mountains that are visible.</pre> |
| 26 | + |
| 27 | +<p><strong>Example 2:</strong></p> |
| 28 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2300-2399/2345.Finding%20the%20Number%20of%20Visible%20Mountains/images/ex2new1.png" style="width: 300px; height: 180px;" /> |
| 29 | +<pre> |
| 30 | +<strong>Input:</strong> peaks = [[1,3],[1,3]] |
| 31 | +<strong>Output:</strong> 0 |
| 32 | +<strong>Explanation:</strong> The diagram above shows the mountains (they completely overlap). |
| 33 | +Both mountains are not visible since their peaks lie within each other. |
| 34 | +</pre> |
| 35 | + |
| 36 | +<p> </p> |
| 37 | +<p><strong>Constraints:</strong></p> |
| 38 | + |
| 39 | +<ul> |
| 40 | + <li><code>1 <= peaks.length <= 10<sup>5</sup></code></li> |
| 41 | + <li><code>peaks[i].length == 2</code></li> |
| 42 | + <li><code>1 <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>5</sup></code></li> |
| 43 | +</ul> |
| 44 | + |
| 45 | + |
| 46 | +## 解法 |
| 47 | + |
| 48 | +<!-- 这里可写通用的实现逻辑 --> |
| 49 | + |
| 50 | +<!-- tabs:start --> |
| 51 | + |
| 52 | +### **Python3** |
| 53 | + |
| 54 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 55 | + |
| 56 | +```python |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +### **Java** |
| 61 | + |
| 62 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 63 | + |
| 64 | +```java |
| 65 | + |
| 66 | +``` |
| 67 | + |
| 68 | +### **TypeScript** |
| 69 | + |
| 70 | +```ts |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | +### **...** |
| 75 | + |
| 76 | +``` |
| 77 | +
|
| 78 | +``` |
| 79 | + |
| 80 | +<!-- tabs:end --> |
0 commit comments