https://leetcode-cn.com/problems/pascals-triangle/
class Solution:
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if numRows == 0:
return []
res = [[1]]
row = [1]
if numRows == 1:
return res
#一层层叠加
for i in range(1, numRows):
new_row = [1]
for j in range(1, i):
new_row.append(row[j-1] + row[j])
new_row.append(1)
row = new_row
res.append(new_row)
return res