```
class Solution(object):
def minPathSum(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
for row in xrange(1,len(grid)):
grid[row][0] += grid[row-1][0]
for col in xrange(1,len(grid[0])):
grid[0][col] += grid[0][col-1]
for i in xrange(1,len(grid)):
for j in xrange(1,len(grid[0])):
grid[i][j] += min(grid[i-1][j],grid[i][j-1])
return grid[len(grid)-1][len(grid[0])-1]
```