Created
December 22, 2018 02:44
-
-
Save qiaoxu123/96f8cd024237bedbf9be6cdaf3df1549 to your computer and use it in GitHub Desktop.
https://leetcode.com/problems/pascals-triangle/
第一种写法:使用两种for循环,使得当前行中的值是上一行的两个数之和
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//复杂度比较高的写法 | |
//原创+参考 | |
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