728x90
https://leetcode.com/problems/pascals-triangle/
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans(numRows);
ans[0].push_back(1);
for(int i=1; i<numRows; i++){
for(int j=0; j<=i; j++){
if(j==0 || j==i) ans[i].push_back(1);
else ans[i].push_back((ans[i-1][j-1]+ans[i-1][j]));
}
}
return ans;
}
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/easy/Array] Best Time to Buy and Sell Stock (0) | 2022.08.16 |
---|---|
[LeetCode/easy/Array] Pascal's triangle II (0) | 2022.08.16 |
[LeetCode/easy/Array] Merge Sorted Array (0) | 2022.08.16 |
[LeetCode/easy/Array] Plus One (0) | 2022.08.16 |
[LeetCode/easy/Array] Search Insert Position (0) | 2022.08.16 |