2025-08-01 04:15:40 +0000 UTC

Pascal’s Triangle

Code

class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        res = [(1, )]
        cur_row = []
        for row in range(1, numRows):
            cur_row.append(1)
            prev_row = res[-1]
            for i in range(1, row):
                cur_row.append(prev_row[i] + prev_row[i - 1])
            cur_row.append(1)
            res.append(tuple(cur_row))
            cur_row.clear()
        return res