]
vector<vector<int>> generate(int numRows) { vector<vector<int>> val; val.resize(numRows); for (int i=0; i<numRows; i++) { //pascal三角形,第i行元素个数为i+1(i从0开始) val[i].resize(i+1); //首位元素都为1 val[i][0]=1; val[i][val[i].size()-1]=1; //中间元素满足:A[k][n]=A[k-1][n-1]+A[k-1][n] for (int j=1; j<val[i].size()-1; j++) { val[i][j]=val[i-1][j-1]+val[i-1][j]; } } return val; }
原文地址:http://blog.csdn.net/lsh_2013/article/details/45849785