难度:Medium
掌握程度:Low
var uniquePaths = function(m, n) {
const memo = [];
#这里push的意思是创建二维数组
for(let i=0;i<n;i++){
memo.push([]);
}
for(let row = 0;row<n;row++){
#row的第一行都为1
memo[row][0] =1;
}
for(let col = 0;col<m;col++){
#cold第一列都为1,参照矩阵写法
memo[0][col]=1;
}
for(let row = 1;row<n;row++){
for(let col = 1;col<m;col++){
#这里是我们说的上面的数和左面的数加和
memo[row][col] = memo[row-1][col]+memo[row][col-1];
}
}
return memo[n-1][m-1];
};