leetcode刷题python之最小路径和

class Solution:
    def minPathSum(self, grid: List[List[int]]) -> int:
        n = len(grid)
        m = len(grid[0])
        for i in range(1, m):
            grid[0][i] += grid[0][i - 1]    
        for j in range(1, n):
            grid[j][0] += grid[j - 1][0]
        for i in range(1, m):
            for j in range(1, n):
                grid[j][i] += min(grid[j - 1][i], grid[j][i - 1])
        # print(grid)
        return grid[n - 1][m - 1]

你可能感兴趣的:(leetcode_python)