> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/dynamic-programming/119.-pascals-triangle-ii.md).

# 119. Pascal's Triangle II

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MehGxHDxbZkStkHWptA%2F-MehKYex_jRlAaDfxq7s%2Fimage.png?alt=media\&token=673c9066-7e36-44cd-a996-9085ae05bf21)

time: O(n^2)

space: O(n)

same as 118, just return last row

```java
class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i <= rowIndex; i++) {
            list.add(0,1);
            for (int j = 1; j < list.size() - 1; j++) {
                list.set(j, list.get(j)+list.get(j+1));
            }
        }
        return list;
    }
}
```
