LeetCode solutions

2350. Find Closest Number to Zero

My accepted Python solution to LeetCode problem 2350, Find Closest Number to Zero, running in 7ms.

  • Difficulty: Easy
  • Python
  • Runtime 7ms
  • Memory 17.8MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 17.8MB, accepted 2026-01-01.

python
class Solution:
    def findClosestNumber(self, nums: List[int]) -> int:
        closest = nums[0]
        for num in nums:
            if abs(num) < abs(closest) or (abs(num) == abs(closest) and num > closest):
                closest = num
        return closest

Source