※ 引述《TonyQ (自立而後立人)》之銘言:
michael0728n正解啦
inp = [2 , -7 , 0, 1, 2 , 3 , 8 , -6 , 5, 0, 9, 2, 0, 1, 2 , 8, 8 , -6 , 5]
max_ = inp[0] * inp[1]
def f(inp):
global max_
v_ = 1
for i in range(0, len(inp)):
v = v_ * inp[i]
if(v == 0):
#v = f(inp[i+1:])
v_ = 1
else:
v_ = v
if(v > max_):
max_ = v
print v, v_
return max_
r = f(inp)
print r
(vincent一看到題目就覺得是O(n),然後跑來和我唸,我就練習一下python XD)