Skip to content

Commit 65f3624

Browse files
add 1779
1 parent cbd6861 commit 65f3624

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1779|[Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1779.java) ||Easy|Array|
1112
|1774|[Closest Dessert Cost](https://leetcode.com/problems/closest-dessert-cost/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1774.java) ||Medium|Greedy|
1213
|1773|[Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1773.java) ||Easy|Array, String|
1314
|1772|[Sort Features by Popularity](https://leetcode.com/problems/sort-features-by-popularity/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1772.java) ||Medium|HashTable, Sort|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1779 {
4+
public static class Solution1 {
5+
public int nearestValidPoint(int x, int y, int[][] points) {
6+
int nearestManDistance = Integer.MAX_VALUE;
7+
int result = -1;
8+
for (int i = 0; i < points.length; i++) {
9+
int[] point = points[i];
10+
if (point[0] == x || point[1] == y) {
11+
int distance = Math.abs(point[0] - x) + Math.abs(point[1] - y);
12+
if (distance < nearestManDistance) {
13+
result = i;
14+
nearestManDistance = distance;
15+
}
16+
}
17+
}
18+
return result;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)