Leetcode 119. Pascal's Triangle II

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

1. Description

Pascal's Triangle II

2. Solution

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

Reference

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