這是python3整個代碼:值沒有改變什麼它應該(9號線)
def rainwater(array):
max_value = max(array)
count = 0
for a in range(0, max_value):
temp = array
for i in range(0, len(temp)):
if temp[i] >= 1:
print(temp)
temp[i] = 1 # somehow this line always changes temp[i] to 0 instead of 1
array[i] = array[i] - temp[i]
array = temp
for i in range(0, len(temp)):
if temp[i] == 1:
del temp[:i]
break
for i in range(0, len(temp) - 1, -1):
if temp[i] == 1:
del temp[i:]
break
if len(temp) <= 1:
return count
for i in range(0, len(temp)):
if temp[i] == 0:
count = count + 1
return count
# driver program -> should return 6
print(rainwater([0,1,0,2,1,0,1,3,2,1,2,1]))
上線9.不知道如何分類出現此問題的問題,但我不能爲我的生活弄清楚這裏缺少的東西。提前致謝。
請檢查並接受答案 –