Skip to content

Commit 20cbe19

Browse files
Create 1637. 两点之间不包含任何点的最宽垂直区域.md
1 parent 0b068b7 commit 20cbe19

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#### 1637. 两点之间不包含任何点的最宽垂直区域
2+
3+
难度:中等
4+
5+
---
6+
7+
给你 `n` 个二维平面上的点 `points` ,其中 `points[i] = [xi, yi]` ,请你返回两点之间内部不包含任何点的  **最宽垂直区域** 的宽度。
8+
9+
**垂直区域** 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 **最宽垂直区域** 为宽度最大的一个垂直区域。
10+
11+
请注意,垂直区域  **边上**  的点  **不在**  区域内。
12+
13+
**示例 1:**
14+
15+
![](https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/10/31/points3.png)
16+
```
17+
输入:points = [[8,7],[9,9],[7,4],[9,7]]
18+
输出:1
19+
解释:红色区域和蓝色区域都是最优区域。
20+
```
21+
22+
**示例 2:**
23+
24+
```
25+
输入:points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
26+
输出:3
27+
```
28+
29+
**提示:**
30+
31+
* `n == points.length`
32+
* `2 <= n <= 10^5`
33+
* `points[i].length == 2`
34+
* `0 <= xi, yi <= 10^9`
35+
36+
---
37+
38+
自定义排序:
39+
40+
无需考虑纵坐标,相邻两点横坐标差的最大值即是所要求的值。
41+
42+
```Java
43+
class Solution {
44+
public int maxWidthOfVerticalArea(int[][] points) {
45+
Arrays.sort(points, (a, b) -> (a[0] - b[0]));
46+
int ans = 0;
47+
for(int i = 1; i < points.length; i++){
48+
ans = Math.max(points[i][0] - points[i - 1][0], ans);
49+
}
50+
return ans;
51+
}
52+
}
53+
```

0 commit comments

Comments
 (0)