```
class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
int row=grid.size(),col=grid[0].size();
for(int i=row-1;i>=0;i--)
{
for(int j=col-1;j>=0;j--)
{
if(i==row-1&&j==col-1)//last point
grid[i][j]=grid[i][j];
if(j==col-1&&i<row-1)//last column
grid[i][j]+=grid[i+1][j];
if(i==row-1&&j<col-1)//last row
grid[i][j]+=grid[i][j+1];
if(i<row-1&&j<col-1)//others
grid[i][j]=min((grid[i][j]+grid[i][j+1]),(grid[i][j]+grid[i+1][j]));
}
}
return grid[0][0];
}
};
```