LeetCode_Pascal's Triangle

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 ;
}
};
上一篇:[css filter]filter在界面实现滤镜效果


下一篇:centos 用户切换