Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8594fbd

Browse files
Create 1779. Find Nearest Point That Has the Same X or Y Coordinate.cpp
1 parent 7d4aa01 commit 8594fbd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int nearestValidPoint(int x, int y, vector<vector<int>>& points) {
4+
int n = points.size(), mn = INT_MAX, ans = -1, manhattan;
5+
for(int i = 0; i < n; i++)
6+
if(points[i][0] == x || points[i][1] == y){
7+
manhattan = abs(x - points[i][0]) + abs(y - points[i][1]);
8+
if(manhattan < mn)
9+
mn = manhattan, ans = i;
10+
}
11+
return ans;
12+
}
13+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /