2239. Find Closest Number to Zero

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

Содержание

LeetCode problem 2239

class Solution:
    def findClosestNumber(self, nums: List[int]) -> int:
        res, d = 0, inf
        for x in nums:
            if (y := abs(x)) < d or (y == d and x > res):
                res, d = x, y
        return res