first try
Verifying solution... Test 1 passed! Test 2 passed! Test 3 passed! [Hidden] Test 4 failed [Hidden] Test 5 failed [Hidden]
This commit is contained in:
parent
49aad951de
commit
422abb6363
25
extra/power-hungry/solution.py
Normal file
25
extra/power-hungry/solution.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
def solution(xs):
|
||||||
|
result = 1
|
||||||
|
max_negative = 0
|
||||||
|
for power in xs:
|
||||||
|
if power == 0:
|
||||||
|
continue
|
||||||
|
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
|
||||||
|
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)
|
||||||
Loading…
x
Reference in New Issue
Block a user