首页 > 编程语言 > 详细

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

时间:2018-10-26 17:08:11      阅读:209      评论:0      收藏:0      [点我收藏+]
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版 礼物的最大价值

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!