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

Обновлено: 2024-03-12
1 мин
[]

Содержание

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