Seongbeom Park 53116f6ff5 finish extra/power-hungry
Submitting solution...
Submission: SUCCESSFUL. Completed in: 16 mins, 49 secs.
2022-05-08 03:44:17 +09:00

33 lines
789 B
Python

def solution(xs):
if len(xs) == 1:
return str(xs[0])
result = 1
max_negative = 0
non_positive_only = True
for power in xs:
if power == 0:
continue
if power > 0:
non_positive_only = False
result *= power
if power < 0:
if max_negative == 0:
max_negative = power
else:
max_negative = max(max_negative, power)
if max_negative < 0 and result < 0:
result /= max_negative
if non_positive_only:
result = 0
return str(result)
tests = [
([2, 0, 2, 2, 0], "8"),
([-2, -3, 4, -5], "60"),
([2, -3, 1, 0, -5], "30"),
]
for i, o in tests:
result = solution(i)
print (i, result == o, result, o)