> For the complete documentation index, see [llms.txt](https://hao-fu-1.gitbook.io/oj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hao-fu-1.gitbook.io/oj/dynamic_programming_i/zou-ge/119.-pascals-triangle-ii.md).

# 119. Pascal's Triangle II

https\://leetcode.com/problems/pascals-triangle-ii/description/

当前行和上一行的i和i-1有关。为了节省空间，可以倒着遍历，那i当前和之前的元素值即上一行的i和i-1的值。

```
/*
 * @lc app=leetcode id=119 lang=cpp
 *
 * [119] Pascal's Triangle II
 */
class Solution {
public:
    vector<int> getRow(int rowIndex) {
        ++rowIndex;
        if (rowIndex == 1) return {1};
        vector<int> cur;
        for (int i = 2; i <= rowIndex; ++i) {
            cur.resize(i);
            cur[0] = 1;
            for (int j = i - 2; j >= 1; --j) cur[j] += cur[j - 1];
            cur[i - 1] = 1;
        } 
        return cur;
    }
};


```
