118. Pascal's Triangle
[Easy] “Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle."
Python3:
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = []
for i in range(0, numRows):
if i == 0:
res.append([1])
else:
last = res[i - 1]
row_inner = [(last[j - 1] + last[j]) for j in range(1, len(last))]
res.append([1] + row_inner + [1])
return res