Python no extra space


  • 0
    G
        def minPathSum(self, grid):
            """
            :type grid: List[List[int]]
            :rtype: int
            """
            m, n = len(grid), len(grid[0])
            
            for j in range(1, n):
                grid[0][j] += grid[0][j-1]
                
            for i in range(1, m):
                grid[0][0] += grid[i][0]
                for j in range(1, n):
                    grid[0][j] = min(grid[0][j-1],grid[0][j]) + grid[i][j]
            return grid[0][-1]

Log in to reply
 

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