I tried a similar logic without extra space:
var minPathSum = function(grid) { let m = grid.length; let n = grid[0].length; for (let i=0; i<m; i++) { for (let j=0; j<n; j++) { if (i==0 && j==0) continue; if (i==0) { grid[i][j]+=grid[i][j-1]; } else if(j==0) { grid[i][j]+=grid[i-1][j]; } else { grid[i][j]+=Math.min(grid[i][j-1], grid[i-1][j]); } } } return grid[m-1][n-1]; };
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I tried a similar logic without extra space: