-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathSolution.java
26 lines (26 loc) · 955 Bytes
/
Solution.java
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
class Solution {
public int minimumDistance(int[][] points) {
TreeMap<Integer, Integer> tm1 = new TreeMap<>();
TreeMap<Integer, Integer> tm2 = new TreeMap<>();
for (int[] p : points) {
int x = p[0], y = p[1];
tm1.merge(x + y, 1, Integer::sum);
tm2.merge(x - y, 1, Integer::sum);
}
int ans = Integer.MAX_VALUE;
for (int[] p : points) {
int x = p[0], y = p[1];
if (tm1.merge(x + y, -1, Integer::sum) == 0) {
tm1.remove(x + y);
}
if (tm2.merge(x - y, -1, Integer::sum) == 0) {
tm2.remove(x - y);
}
ans = Math.min(
ans, Math.max(tm1.lastKey() - tm1.firstKey(), tm2.lastKey() - tm2.firstKey()));
tm1.merge(x + y, 1, Integer::sum);
tm2.merge(x - y, 1, Integer::sum);
}
return ans;
}
}