119. Pascal‘s Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal‘s triangle.
Note that the row index starts from 0.
In Pascal‘s triangle, each number is the sum of the two numbers directly above it.
Example:
Input: 3 Output: [1,3,3,1]
题意:二维数组表示的杨辉三角,求出给定行的数据
代码如下:
/** * @param {number} rowIndex * @return {number[]} */ var getRow = function(rowIndex) { let res=[]; let temp=2; for(let i=0;i<=rowIndex;i++){ res[i]=[] if(i>0) res[i].push(1) for(let j=1;j<i;j++){ res[i].push(res[i-1][j]+res[i-1][j-1]); } res[i].push(1); } return res.pop(); };
原文:https://www.cnblogs.com/xingguozhiming/p/10828489.html