```
class Solution(object):
def minPathSum(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
if not grid or not grid[0]: return 0
m=len(grid)
n=len(grid[0])
helper=[float("inf")]*(n+1)
helper[1]=0
for i in range(m):
for j in range(1,n+1):
helper[j]=min(helper[j-1],helper[j])+grid[i][j-1]
return helper[-1]
```