1779. Find Nearest Point That Has the Same X or Y Coordinate

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1779

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