3
def findClosestNumber1(self, nums: List[int]) -> int:4
return min(nums, key=lambda x: (abs(x), -x))6
def findClosestNumber2(self, nums: List[int]) -> int:7
return min(nums, key=lambda x: abs(x - 0.1))9
def findClosestNumber3(self, nums: List[int]) -> int:10
return max((-abs(x), x) for x in nums)[1]12
def findClosestNumber4(self, nums: List[int]) -> int:13
return -min(zip(map(abs, nums), map(neg, nums)))[1]15
def findClosestNumber5(self, nums: List[int]) -> int:16
a = min(map(abs, nums))17
return a if a in nums else -a19
def findClosestNumber6(self, nums: List[int]) -> int:20
a = abs(min(nums, key=abs))21
return a if a in nums else -a23
def findClosestNumber7(self, nums: List[int]) -> int:24
x = min(nums, key=abs)25
return x if x >= 0 or -x not in nums else -x27
def findClosestNumber8(self, nums: List[int]) -> int:28
return min(sorted(nums, reverse=True), key=abs)30
def findClosestNumber9(self, nums: List[int]) -> int:37
return a if a in nums else -a39
def findClosestNumberA(self, nums: List[int]) -> int:48
return pos if pos <= -neg else neg50
def findClosestNumberB(self, nums: List[int]) -> int:54
if x < pos and neg < x:59
return pos if pos <= -neg else neg61
def findClosestNumberC(self, nums: List[int]) -> int:65
if neg < x and x < pos:70
return pos if pos <= -neg else neg72
def findClosestNumberD(self, nums: List[int]) -> int:81
return pos if pos <= -neg else neg83
def findClosestNumber(84
self, nums: List[int], timess=defaultdict(lambda: [0] * 10), testcase=[0]86
name = "findClosestNumber"88
getattr(self, s) for s in dir(self) if s.startswith(name) and s != name90
expect = dummy = object()91
from time import perf_counter as time95
for solution in solutions:97
result = solution(nums)101
assert result == expect102
timess[solution.__name__][i] += end - start104
if testcase[0] == 224:105
for name, times in sorted(timess.items(), key=lambda nt: sorted(nt[1])):106
print(name, *(f"{t*1e3:6.2f} ms" for t in sorted(times)[:3]))