劍指offer python版 禮物的最大價值
阿新 • • 發佈:2018-10-26
臨時 python sel temp pan range val offer 數值
class Solution: def getmaxValue(self, values, rows, cols): if not values or rows<=0 or cols <=0: return 0 # 用於存放中間數值的臨時數組 temp = [0] * cols for i in range(rows): for j in range(cols): left = 0 up = 0if i > 0: up = temp[j] if j > 0: left = temp[j-1] temp[j] = max(up,left) + values[i*rows+j] return temp[-1] s = Solution() print(s.getmaxValue([1,10,3,8,12,2,9,6,5,7,4,11,3,7,16,5],4,4))
劍指offer python版 禮物的最大價值