标签:leetcode
Given 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> > res; for (int i = 0; i < numRows; ++i) { res.push_back(vector<int>()); res[i].push_back(1); for (int j = 1; j < i; ++j) res[i].push_back(res[i-1][j]+res[i-1][j-1]); if (i) res[i].push_back(1); } return res; } };
Pascal's Triangle,布布扣,bubuko.com
标签:leetcode
原文地址:http://blog.csdn.net/dream_you_to_life/article/details/32715043