Python solution , DP, 52 ms

  • 1

    The fastest time: 52 ms,beats 100.00% .

    def minPathSum(self, grid):
        m, n = len(grid), len(grid[0])
        dp = [0] * n
        for i in xrange(m):
            dp[0] += grid[i][0]
            for j in xrange(1, n):
                dp[j] = (min(dp[j], dp[j-1]) or dp[j-1]) + grid[i][j]
        return dp[-1]

Log in to reply

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