LeetCode_Pascal's Triangle

时间:2023-03-08 22:31:43
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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<vector<int>> result;
if(numRows <= ) return result; vector<int> first;
first.push_back(); result.push_back(first); for(int i = ; i < numRows ; i++)
{
vector<int> temp(i+);
for(int j = ; j < i+ ; j++){
if( j == || j == i){
temp[j] = ;continue;
}else{
temp[j] = result[i-][j] + result[i-][j-] ;
continue;
}
}
result.push_back(temp);
} return result ;
}
};