码迷,mamicode.com
首页 > 编程语言 > 详细

剑指offer python版 礼物的最大价值

时间:2018-10-26 17:55:22      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:最大   col   max   div   code   bsp   中间   off   style   

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 = 0 
                if 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版 礼物的最大价值

标签:最大   col   max   div   code   bsp   中间   off   style   

原文地址:https://www.cnblogs.com/xzm123/p/9857356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!