class Solution: # @param grid, a list of lists of integers # @return an integer def minPathSum(self, grid): row=len(grid) col=len(grid[0]) if row*col==0: return 0 dp=[[grid[j][i] for i in range(col)] for j in range(row)] for i in range(1,row): dp[i][0]=dp[i-1][0]+grid[i][0] for j in range(1,col): dp[0][j]=dp[0][j-1]+grid[0][j] for i in range(1,row): for j in range(1,col): dp[i][j]=grid[i][j]+min(dp[i-1][j],dp[i][j-1]) return dp[row-1][col-1]
Monday, September 8, 2014
Leetcode: Minimum Path Sum @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment