Find Closest Number to Zero
Return the value of nums that is closest to 0. If two values are equally close (like -2 and 2), return the larger one.
Example 1
nums [-4,-2,1,4,8]
returns 1
1 is only 1 away from 0.
Example 2
nums [2,-1,1]
returns 1
-1 and 1 tie, so return 1.
Constraints
1 <= len(nums) <= 30-100 <= nums[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.