Skip to content

Commit

Permalink
added Pascals Triangle || problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mukul96 committed Nov 7, 2022
1 parent 75500d6 commit 9266a00
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Dynamic Programming/Pascals Triangle ||.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Solution
{
public:
vector<int> getRow(int rowIndex)
{
int numRows = rowIndex + 1;
vector<vector<int> > res;
vector<int> temp;
temp.push_back(1);
res.push_back(temp);
if (numRows == 1)
{
return temp;
}
temp.push_back(1);
res.push_back(temp);
int count = 2;
while (count < numRows)
{
int n = res.size();
int j = res[n - 1].size();
vector<int> temp;
temp.push_back(1);
for (int i = 0; i < j - 1; i++)
{
temp.push_back(res[n - 1][i] + res[n - 1][i + 1]);
}
temp.push_back(1);
res.push_back(temp);
count++;
}
return res[numRows - 1];
}
};

0 comments on commit 9266a00

Please sign in to comment.