---
title: "118. Pascal's Triangle"
url: "https://laigary.com/interview/coding/118-pascals-triangle"
type: "note"
section: "coding"
date: "2023-10-31"
updated: "2023-10-31"
tags: ["Recursion", "Array"]
---

# 118. Pascal's Triangle

[118. Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)  

```python
class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        def helper(numRows):
            if numRows == 1:
                res.append([1])
                return [1]
            prev = helper(numRows - 1)
            curr = []
            for i in range(len(prev) - 1):
                curr.append(prev[i] + prev[i+1])
            res.append([1] + curr + [1])
            return [1] + curr + [1]

        res = []
        helper(numRows)
        return res
```
