var minPathSum = function(grid) {
const numRow = grid.length
const numCol = grid[0].length
const obj ={}
const path =(row,col)=>{
if(obj[row+ ':' +col] !== undefined){
return obj[row+ ':' +col]
}
let right = Infinity
let down = Infinity
if(col<numCol -1){
right= path(row,col+1)
}
if(row <numRow-1){
down= path(row+1,col)
}
if(right === Infinity && down === Infinity){
right = down = 0
}
const result = grid[row][col]+ Math.min(right,down);
obj[row+ ':' +col] =result;
return result
}
return path(0,0)
};