```
class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
int m = grid.size();
if (m < 1) return 0;
int n = grid[0].size();
if (n < 1) return 0;
unsigned int row[n + 1] = {0};
memset(row, 0xff, sizeof(row));
row[1] = 0;
for (int i = 0; i < m; i++) {
for (int j = 0, k = 1; j < n; j++, k++) {
row[k] = min(row[j], row[k]) + grid[i][j];
}
}
return row[n];
}
};
```