Leetcode 118 Pascal's Triangle(水)

题目连接:Leetcode 118 Pascal's Triangle

解题思路:按照题目思路模拟,记录每一行。

class Solution {
	public:
		vector> generate(int numRows) {
			vector> ans;
			vector cur;
			for (int i = 0; i < numRows; i++) {
				cur.push_back(1);
				for (int j = i-1; j > 0; j--)
					cur[j] += cur[j-1];
				ans.push_back(cur);
			}
			return ans;
		}
};

你可能感兴趣的:(Leetcode)