-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode1637.java
More file actions
34 lines (30 loc) · 1.27 KB
/
LeetCode1637.java
File metadata and controls
34 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Arrays;
public class LeetCode1637 {
public static void main(String[] args) {
// 输入:points = [[8,7],[9,9],[7,4],[9,7]]
// 输出:1
System.out.println(
new Solution1637().maxWidthOfVerticalArea(new int[][] { { 8, 7 }, { 9, 9 }, { 7, 4 }, { 9, 7 } }));
// 输入:points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
// 输出:3
System.out.println(
new Solution1637().maxWidthOfVerticalArea(
new int[][] { { 3, 1 }, { 9, 0 }, { 1, 0 }, { 1, 4 }, { 5, 3 }, { 8, 8 } }));
// 输入:points = [[2,4],[10,10],[6,8],[6,8],[6,10],[8,6],[5,3]]
// 输出:3
System.out.println(
new Solution1637().maxWidthOfVerticalArea(
new int[][] { { 2, 4 }, { 10, 10 }, { 6, 8 }, { 6, 8 }, { 6, 10 }, { 8, 6 }, { 5, 3 } }));
}
}
class Solution1637 {
public int maxWidthOfVerticalArea(int[][] points) {
Arrays.sort(points, (a, b) -> (a[0] - b[0]));
// System.out.println(Arrays.deepToString(points));
int ans = points[1][0] - points[0][0];
for (int i = 2; i < points.length; i++) {
ans = Math.max(points[i][0] - points[i - 1][0], ans);
}
return ans;
}
}