# 118. Pascal's Triangle

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MehGUyDz3_UNFK4Jlyw%2F-MehGruaqusl3nMOTMvu%2Fimage.png?alt=media\&token=79e6ab7f-4780-45a6-921f-c16a23353449)

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MehGUyDz3_UNFK4Jlyw%2F-MehGufJ-bgZ4o59dbJs%2Fimage.png?alt=media\&token=8e7eb11e-0f7d-45e3-8354-66992bf4c358)



time: O(n^2)

space: O(n)

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