1779. Find Nearest Point That Has the Same X or Y Coordinate
On This Page
class Solution:
def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:
res, mi = -1, inf
for i, (a, b) in enumerate(points):
if a == x or b == y:
d = abs(a - x) + abs(b - y)
if mi > d:
res, mi = i, d
return res