My python Solution


  • 0
    S
    class Solution(object):
    def minPathSum(self, grid):
        """
        :type grid: List[List[int]]
        :rtype: int
        """
        if not grid or not grid[0]: return 0
        m=len(grid)
        n=len(grid[0])
        helper=[float("inf")]*(n+1)
        helper[1]=0
        for i in range(m):
            for j in range(1,n+1):
                helper[j]=min(helper[j-1],helper[j])+grid[i][j-1]
        return helper[-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.