Leetcode-Solutions icon indicating copy to clipboard operation
Leetcode-Solutions copied to clipboard

No need to check for abs(num) again which increases the TC

Open Sivaramjallu001 opened this issue 1 year ago • 0 comments

class Solution: def findClosestNumber(self, nums: List[int]) -> int: min_distance = float("inf") res = None for num in nums: distance = abs(num) if distance < min_distance or (distance == min_distance and num > res): min_distance = distance # res = num return res

Sivaramjallu001 avatar Aug 07 '24 07:08 Sivaramjallu001