题目描述:
//题解
class Solution { public: vector<vector<int> > ret; vector<vector<int>> generate(int numRows) { if(numRows <= 0) return ret; for(int i = 1 ; i <= numRows; i++ ){ if(i == 1){ vector<int> tmp; tmp.push_back(1); ret.push_back(tmp); } else if( i == 2){ vector<int> tmp; tmp.push_back(1); tmp.push_back(1); ret.push_back(tmp); } else{ vector<int> last = ret.back(); vector<int> tmp; tmp.push_back(1); for(int j = 1; j < i-1; j++ ){ int num = last.at(j-1)+last.at(j); tmp.push_back(num); } tmp.push_back(1); ret.push_back(tmp); } } return ret; } };