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; } };
原文:http://blog.csdn.net/wyj7260/article/details/39806523