class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector< vector<int> > result;
vector<int> innerResult;
int i = 0;
int j = 0;
for(i = 0; i < numRows; i++){
innerResult.clear();
for(j = 0; j <= i; j++){
if(j == 0 || j == i){
innerResult.push_back(1);
} else {
innerResult.push_back(result[i-1][j-1]+result[i-1][j]);
}
}
result.push_back(innerResult);
}
return result;
}
};
Leetcode Pascal's Triangle
最新推荐文章于 2021-02-16 00:39:16 发布