2239. Find Closest Number to Zero
Содержание
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