- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1779.java
21 lines (20 loc) · 742 Bytes
/
_1779.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
packagecom.fishercoder.solutions.secondthousand;
publicclass_1779 {
publicstaticclassSolution1 {
publicintnearestValidPoint(intx, inty, int[][] points) {
intnearestManDistance = Integer.MAX_VALUE;
intresult = -1;
for (inti = 0; i < points.length; i++) {
int[] point = points[i];
if (point[0] == x || point[1] == y) {
intdistance = Math.abs(point[0] - x) + Math.abs(point[1] - y);
if (distance < nearestManDistance) {
result = i;
nearestManDistance = distance;
}
}
}
returnresult;
}
}
}