LeetCode 118. Pascal’s Triangle
Solution1:我的答案
简单题,一遍过!
class Solution {
public:
vector<vector<int>> generate(int numRows) {
if (!numRows) return {};
vector<vector<int> > res;
vector<int> temp = {1};
for (int i = 0; i < numRows; i++) {
res.push_back(temp);
temp.push_back(1);
for (int j = temp.size() - 2; j >= 1; j--)
temp[j] += temp[j - 1];
}
return res;
}
};