@laigary.com~/interview/coding/118-pascals-triangle.md$
$ cat ./coding/118-pascals-triangle.md
[Coding]·2023-10-31·1 min read

118. Pascal's Triangle

118. Pascal's Triangle

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