Skip to content

Instantly share code, notes, and snippets.

@qiaoxu123
Created December 22, 2018 02:44
Show Gist options
  • Save qiaoxu123/96f8cd024237bedbf9be6cdaf3df1549 to your computer and use it in GitHub Desktop.
Save qiaoxu123/96f8cd024237bedbf9be6cdaf3df1549 to your computer and use it in GitHub Desktop.
https://leetcode.com/problems/pascals-triangle/ 第一种写法:使用两种for循环,使得当前行中的值是上一行的两个数之和
//复杂度比较高的写法
//原创+参考
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> array(numRows);
for(int i = 0;i < numRows;++i){ //第几行
array[i].resize(i+1);
array[i][0] = array[i][i] = 1;
for(int j = 1;j < i;++j){ //每行第几个
array[i][j] = array[i-1][j-1] + array[i-1][j];
}
}
return array;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment