Leetcode/python/118_pascals_triangle.py
2024-04-30 16:56:00 +01:00

8 lines
277 B
Python

class Solution:
def generate(self, numRows: int) -> List[List[int]]:
rows = []
for i in range(1, numRows + 1):
row = [1 if j == 0 or j >= i - 1 else rows[i-2][j-1]+rows[i-2][j] for j in range(i)]
rows.append(row)
return rows