let minPathSum = function(grid) {
if(!grid || !grid.length) return 0;
let maxRow = grid.length, maxCol = grid[0].length;
function sum(row, col, total, path = '') {
const val = grid[row][col] + total; //?
if (row === maxRow - 1 && col === maxCol - 1) {
return val;
} //?
if (row === maxRow - 1) {
return sum(row, col + 1, val);
}
else if (col === maxCol - 1) {
return sum(row + 1, col, val);
} else {
const down = sum(row + 1, col, val);
const right = sum(row, col + 1, val);
return Math.min(down, right);
}
}
return sum(0, 0, 0);
};