728x90
https://leetcode.com/problems/pascals-triangle-ii/
vector<int> getRow(int rowIndex) {
vector<vector<int>> ans(rowIndex+1);
ans[0].push_back(1);
for(int i=1; i<=rowIndex; 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[rowIndex];
}
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode/easy/Array] Single Number (0) | 2022.08.16 |
---|---|
[LeetCode/easy/Array] Best Time to Buy and Sell Stock (0) | 2022.08.16 |
[LeetCode/easy/Array] Pascal's triangle (0) | 2022.08.16 |
[LeetCode/easy/Array] Merge Sorted Array (0) | 2022.08.16 |
[LeetCode/easy/Array] Plus One (0) | 2022.08.16 |