File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ them with C++ Language.
76
76
| 121 | [ Best Time to Buy and Sell Stock] | [ C] ( src/121.c ) |
77
77
| 120 | [ Triangle] | [ C] ( src/120.c ) |
78
78
| 119 | [ Pascal's Triangle II] | |
79
- | 118 | [ Pascal's Triangle] | |
79
+ | 118 | [ Pascal's Triangle] | [ C ] ( src/118.cpp ) |
80
80
| 117 | [ Populating Next Right Pointers in Each Node II] | |
81
81
| 116 | [ Populating Next Right Pointers in Each Node] | |
82
82
| 115 | [ Distinct Subsequences] | |
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+
4
+ using namespace std ;
5
+
6
+ class Solution {
7
+ public:
8
+ vector<vector<int > > generate (int numRows) {
9
+ vector<vector<int > > ans;
10
+
11
+ for (int i = 0 ; i < numRows; i++) {
12
+ ans.push_back (vector<int >(i + 1 , 0 ));
13
+ ans[i][0 ] = 1 ;
14
+ for (int j = 1 ; j < i; j++) {
15
+ ans[i][j] = ans[i - 1 ][j - 1 ] + ans[i - 1 ][j];
16
+ }
17
+ ans[i][i] = 1 ;
18
+ }
19
+ return ans;
20
+ }
21
+ };
22
+
23
+ int main () {
24
+ Solution s;
25
+ vector<vector<int > > ret;
26
+ ret = s.generate (5 );
27
+
28
+ for (unsigned i = 0 ; i < ret.size (); i++) {
29
+ for (unsigned j = 0 ; j < i + 1 ; j++) {
30
+ cout << ret[i][j] << ' ' ;
31
+ }
32
+ cout << endl;
33
+ }
34
+ return 0 ;
35
+ }
You can’t perform that action at this time.
0 commit comments