Leetcode 118 Pascal’s Triangle
#include <vector>
using namespace std;
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> triangle;
if(numRows == 0)
return triangle;
vector<int> currentRow(1,1);
vector<int> lastRow;
triangle.push_back(currentRow);
for(int i = 1; i < numRows; i ++)
{
lastRow = currentRow;
currentRow.clear();
currentRow.push_back(1);
for(int j = 0;j < lastRow.size() - 1;j ++)
{
currentRow.push_back(lastRow[j]+lastRow[j+1]);
}
currentRow.push_back(1);
triangle.push_back(currentRow);
}
return triangle;
}
};