题解 | #矩阵的最小路径和#

矩阵的最小路径和

http://www.nowcoder.com/practice/7d21b6be4c6b429bb92d219341c4f8bb

#
# 
# @param matrix int整型二维数组 the matrix
# @return int整型
#
class Solution:
    def minPathSum(self , matrix ):
        # write code here
        m = len(matrix)
        n = len(matrix[0])
        temp = matrix
        for i in range(0, m):
            for j in range(0, n):
                if(i==0 and j==0):
                    temp[i][j] = temp[i][j]
                elif i==0 and j>0:
                    temp[i][j] += temp[i][j-1]
                elif j==0 and i>0:
                    temp[i][j] += temp[i-1][j]
                else:
                    temp[i][j] += min(temp[i-1][j],temp[i][j-1])
        return temp[m-1][n-1]
全部评论

相关推荐

浩浩没烦恼:一二面加起来才一个小时? 我一面就一个小时多了
点赞 评论 收藏
分享
09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务