Find Nearest Point That Has the Same X or Y Coordinate LeetCode solution in Python

1
# Runtime: 689 ms (Top 99.93%) | Memory: 19.5 MB (Top 5.79%)
2
class Solution:
3
def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:
4
minDist = math.inf
5
ans = -1
6
for i in range(len(points)):
7
if points[i][0] == x or points[i][1] == y:
8
manDist = abs(points[i][0] - x) + abs(points[i][1] - y)
9
if manDist < minDist:
10
ans = i
11
minDist = manDist
12
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0