第八十七天:力扣119题,杨辉三角 II
地址:leetcode-cn.com/problems/pa…
思路:杨辉三角 取所需位置值
var getRow = function(rowIndex) {
let res = [];
for(let i = 0; i <= rowIndex; i++)
{
const arr = new Array(i+1).fill(1);
for(let j = 1; j < arr.length - 1; j++)
{
arr[j] = res[i - 1][j - 1] + res[i - 1][j];
}
res.push(arr);
}
return res[rowIndex];
};
执行用时:72 ms, 在所有 JavaScript 提交中击败了96.14%的用户
内存消耗:37.7 MB, 在所有 JavaScript 提交中击败了73.60%的用户