var generate = function(numRows) {
let res = [];
if(numRows === 0)return res;
res.push([1]);
if(numRows === 1)return res;
res.push([1,1]);
if(numRows === 2)return res;
for(let i = 3; i <= numRows; i++){
let answer = new Array(i);
res.push(answer);
answer[0] = 1;
answer[answer.length - 1] = 1;
for(let j = 1; j < answer.length - 1; j++)
answer[j] = res[i - 2][j - 1] + res[i - 2][j];
}
return res;
};
JS 力扣刷题 118. 杨辉三角
最新推荐文章于 2024-09-16 17:05:22 发布
本文介绍了一个名为 Vargenerate 的函数,用于递归生成数独矩阵。通过逐步构建和调整数组,该函数展示了如何从基础单元格开始,利用前两步的递推公式填充更大的数独。这对于理解递归算法在解决数独问题中的应用具有重要意义。
摘要由CSDN通过智能技术生成