class Solution:
def generate(self, numRows: int) -> List[List[int]]:
re_pot = [[0]*i for i in range(1, numRows + 1)]
for i in range(numRows):
re_pot[i][0], re_pot[i][-1] = 1, 1
if numRows <= 2:
return re_pot
for i in range(2, numRows):
for j in range(1, i + 1):
if re_pot[i][j]:
continue
else:
re_pot[i][j] = re_pot[i - 1][j] + re_pot[i - 1][j - 1]
return re_pot
leetcode118杨辉三角(python3)
最新推荐文章于 2024-09-07 19:07:25 发布