β back to unit
Medium
# searching medium
Closest to Zero
The submarine wants the depth reading closest to the surface β zero is sea level, negatives are underwater. π
You get a list of nums (at least one). Print the number closest to zero. On a tie (like -3 and 3), the first one seen wins.
Example:
Input: nums = [-7, 4, -2, 9]
Output: -2
The distances from zero are 7, 4, 2, 9 β the smallest is 2, belonging to -2.
π‘ need a hint?
srch-closest-to-zero.pyπ given lines are locked β write your code in between
loading...