Skip to content

Commit 9266a00

Browse files
committed
added Pascals Triangle || problem
1 parent 75500d6 commit 9266a00

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution
2+
{
3+
public:
4+
vector<int> getRow(int rowIndex)
5+
{
6+
int numRows = rowIndex + 1;
7+
vector<vector<int> > res;
8+
vector<int> temp;
9+
temp.push_back(1);
10+
res.push_back(temp);
11+
if (numRows == 1)
12+
{
13+
return temp;
14+
}
15+
temp.push_back(1);
16+
res.push_back(temp);
17+
int count = 2;
18+
while (count < numRows)
19+
{
20+
int n = res.size();
21+
int j = res[n - 1].size();
22+
vector<int> temp;
23+
temp.push_back(1);
24+
for (int i = 0; i < j - 1; i++)
25+
{
26+
temp.push_back(res[n - 1][i] + res[n - 1][i + 1]);
27+
}
28+
temp.push_back(1);
29+
res.push_back(temp);
30+
count++;
31+
}
32+
return res[numRows - 1];
33+
}
34+
};

0 commit comments

Comments
 (0)