Question1
![图片标题 图片说明](https://i-blog.csdnimg.cn/blog_migrate/ef73a72162b008ab689965e1a22ba7fb.png)
/**
*
* @param numRows int整型
* @return int整型二维数组
*/
function generate( numRows ) {
if(numRows<=0) return [];
if(numRows==1) return [[1]];
if(numRows==2) return [[1],[1,1]];
var res = [[1],[1,1]]
for(var i=2;i<numRows;i++){
var temp=[];
for(var j=0;j<res[i-1].length-1;j++){
temp.push(res[i-1][j]+res[i-1][j+1])
}
temp.unshift(1);
temp.push(1);
res.push(temp);
}
return res;
}
module.exports = {
generate : generate
};
Question2
![图片标题 图片说明](https://i-blog.csdnimg.cn/blog_migrate/ad8e0de1c63bdc8f3df6a8b0e4f4dae9.png)
k=0 返回的是第一行
/**
*
* @param rowIndex int整型
* @return int整型一维数组
*/
function getRow( rowIndex ) {
// write code here
if(rowIndex<=0) return [1];
if(rowIndex==1) return [1,1];
var res = [[1],[1,1]]
for(var i=2;i<=rowIndex;i++){
var temp=[];
for(var j=0;j<res[i-1].length-1;j++){
temp.push(res[i-1][j]+res[i-1][j+1])
}
temp.unshift(1);
temp.push(1);
res.push(temp);
}
return res[rowIndex];
}
module.exports = {
getRow : getRow
};