[LeetCode]119. Pascal's Triangle II
程序员文章站
2022-04-01 12:05:36
...
[LeetCode]119. Pascal’s Triangle II
题目描述
思路
直接计算二项式系数会出现乘法上溢
考虑动态规划
代码
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res(rowIndex + 1);
res[0] = 1;
for (int i = 1; i <= rowIndex; ++i) {
for (int j = i; j > 0; j--) {
res[j] += res[j - 1];
}
}
return res;
}
};
int main() {
Solution s;
vector<int> res = s.getRow(13);
for (int num : res)
cout << num << " ";
cout << endl;
system("pause");
return 0;
}
推荐阅读
-
Leetcode No.119 Pascal's Triangle II(c++实现)
-
杨辉三角(pascal's triangle)
-
LeetCode-119. Pascal's Triangle II
-
119. Pascal's Triangle II [杨辉三角形2]
-
119. Pascal's Triangle II
-
leetcode -- 119. Pascal's Triangle II
-
2018.05.03 leetcode #119. Pascal's Triangle II
-
【leetcode】119. Pascal's Triangle II
-
LeetCode 119. Pascal's Triangle II
-
[LeetCode]119. Pascal's Triangle II