Steward
分享是一種喜悅、更是一種幸福
程式語言 - LeetCode - C++ - 119. Pascal's Triangle II
題目:

方法:
從右往左更新,避免更新到舊的 row[j] = row[j] + row[j - 1]
解答:
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> ans(rowIndex + 1, 1);
for (int i = 2; i <= rowIndex; ++i) {
for (int j = i - 1; j > 0; --j) {
ans[j] += ans[j - 1];
}
}
return ans;
}
};