You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varminPathSum=function(grid){letrow=grid.length,col=grid[0].length// calc boundaryfor(leti=1;i<row;i++)// calc first colgrid[i][0]+=grid[i-1][0]for(letj=1;j<col;j++)// calc first rowgrid[0][j]+=grid[0][j-1]for(leti=1;i<row;i++)for(letj=1;j<col;j++)grid[i][j]+=Math.min(grid[i-1][j],grid[i][j-1])returngrid[row-1][col-1]};
Activity
sisterAn commentedon Jan 5, 2021
1、DP方程
当前项最小路径和 = 当前项值 + 上项或左项中的最小值
grid[i][j] += Math.min( grid[i - 1][j], grid[i][j - 1] )2、边界处理
grid的第一行与第一列 分别没有上项与左项 故单独处理计算起项最小路径和
计算第一行:
计算第一列:
3、代码实现
cutie6 commentedon Jan 6, 2021
这里计算的方向是从右下角到左上角吧
fengmiaosen commentedon Aug 1, 2022
TonyZhang1993 commentedon Feb 5, 2024
看了labuladong 写的 click here