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%)2class Solution:3def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:4minDist = math.inf5ans = -16for i in range(len(points)):7if points[i][0] == x or points[i][1] == y:8manDist = abs(points[i][0] - x) + abs(points[i][1] - y)9if manDist < minDist:10ans = i11minDist = manDist12return ans