Pascal's Triangle
Pascal's Triangle
Total Accepted: 38612 Total Submissions: 126553Given 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) { vector<vector<int>> V(numRows); int i,j,c; for(i=0;i<numRows;i++) { for(j=0;j<=i;j++) { if(j==0||j==i) c=1; else c=V[i-1][j]+V[i-1][j-1]; V[i].push_back(c); } } return V; } };
版权声明:本文为博主原创文章,未经博主允许不得转载。