Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]很简单的一题
class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector<vector<int> > ans;
vector<int> temp;
for(int num = 0;num < numRows;num++)
{
temp.clear();
temp.push_back(1);
int i = 0;
while(i<num-1)
{
temp.push_back(ans[num-1][i] + ans[num-1][i+1]);
i++;
}
if(num!=0) temp.push_back(1);
ans.push_back(temp);
}
return ans;
}
};