class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> arr;
vector<int> rows;
for(int i = 0; i < numRows; i++) {
rows.clear();
for(int j = 0; j < i+1; j++) {
if(j == 0 || j == i) rows.push_back(1);
else rows.push_back(arr[i-1][j-1] + arr[i-1][j]);
}
arr.push_back(rows);
}
return arr;
}
};
'Problem Solving > 리트코드(leetcode)' 카테고리의 다른 글
Summary Ranges (0) | 2022.01.16 |
---|---|
Single Number (0) | 2022.01.16 |
Count Primes (0) | 2022.01.16 |
[Leetcode/C++] 66. Plus One (0) | 2022.01.16 |
[Leetcode/C++] 455. Assign Cookies (0) | 2022.01.16 |