标签:
/* 杨辉三角的简单应用 res[i][j] = res[i-1][j]+res[i-1][j-1](j>0&&j<i) res[i][j] = 1 (j == 0|| j==i) */ class Solution { public: vector<vector<int> > generate(int numRows) { vector<vector<int> >res; for(int i = 0 ; i < numRows ; i++){ res.push_back(vector<int>()); for(int j = 0 ; j <= i ; j++){ if(j == 0 || j == i) { res[i].push_back(1); }else { res[i].push_back(res[i-1][j]+res[i-1][j-1]); } } } return res; } };
标签:
原文地址:http://www.cnblogs.com/llei1573/p/4430200.html