107. Binary Tree Level Order Traversal II

来源:互联网 发布:java 启动事务 编辑:程序博客网 时间:2024/06/07 07:08

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>> result;if(numRows==0) return result;for (int i = 0; i < numRows; ++i){vector<int> tmp;for (int j = 0; j < i+1; ++j){if(j==0||j==i){tmp.push_back(1);}else{tmp.push_back(result[i-1][j-1]+result[i-1][j]);}}result.push_back(tmp);tmp.clear();}return result;    }};