118. Pascal's Triangle
题目简介
/**
* @param {number} numRows
* @return {number[][]}
*/
题目给我们一个数字 numRows
要求我们返回 Pascal's triangle 从第 1 行到第 numRows 行的所有元素组成的数组
Javascript
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function (numRows) {
const res = []
for (let i = 0; i < numRows; i++) {
const arr = new Array(i + 1).fill(1)
for (let j = 1; j < i; j++) {
arr[j] = res[i-1][j] + res[i-1][j-1]
}
res.push(arr)
}
return res
};