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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.8MB, accepted 2026-01-01.
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