5 lines Python DP


  • 0
    J
    def minPathSum(self, grid):
            f = [0] + [1e10] * (len(grid[0]) - 1)
            for row in grid:
                for m in xrange(len(grid[0])):
                    f[m] = row[m] + min(f[m - 1] if m > 0 else f[m], f[m])
            return f[-1]

Log in to reply
 

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