Skip to content

Commit 55a1577

Browse files
authored
Merge pull request neetcode-gh#1480 from PritomKarmokar/cpp-solution-pascals-triangle
Adding 118-Pascals-Triangle.cpp
2 parents c7b5098 + 8233aeb commit 55a1577

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cpp/118-Pascals-Triangle.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> generate(int numRows)
4+
{
5+
vector<vector<int>> ret;
6+
7+
for(int i = 0; i < numRows ; i++){
8+
vector<int> row(i+1, 1);
9+
for(int j = 1; j < i ; j++){
10+
row[j] = ret[i-1][j] + ret[i-1][j-1];
11+
}
12+
ret.push_back(row);
13+
}
14+
15+
return ret;
16+
}
17+
};

0 commit comments

Comments
 (0)