classSolution(object):defminPathSum(self,grid):""" :type grid: List[List[int]] :rtype: int """# dp[i][j]: min path until grid[i][j]ifnotgrid:return0row=len(grid)col=len(grid[0])ret=[[0]*(col)foriinrange(row)]foriinrange(0,row):forjinrange(0,col):ifi==0andj==0:ret[i][j]=grid[i][j]elifi==0:ret[i][j]=ret[i][j-1]+grid[i][j]elifj==0:ret[i][j]=ret[i-1][j]+grid[i][j]else:ret[i][j]=min(ret[i-1][j],ret[i][j-1])+grid[i][j]returnret[row-1][col-1]