We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0a380b3 commit 4152ff4Copy full SHA for 4152ff4
118. Pascal's Triangle 1
@@ -0,0 +1,19 @@
1
+class Solution {
2
+public:
3
+ vector<vector<int>> generate(int numRows) {
4
+ vector<vector<int>> triangle;
5
+
6
+ for (int i = 0; i < numRows; ++i) {
7
+ vector<int> row(i + 1, 1); // Create a row with all 1s
8
9
+ // Fill the middle elements
10
+ for (int j = 1; j < i; ++j) {
11
+ row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
12
+ }
13
14
+ triangle.push_back(row);
15
16
17
+ return triangle;
18
19
+};
0 commit comments