Leetcode 118. Pascal's Triangle

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Pascal's Triangle

2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> result;
for(int i = 0; i < numRows; i++) {
vector<int> nums(i + 1, 1);
result.push_back(nums);
for(int j = 1; j < i; j++) {
result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
}
}
return result;
}
};

Reference

  1. https://leetcode.com/problems/pascals-triangle/description/
如果有收获,可以请我喝杯咖啡!