题目:
给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。

示例 1:
输入: rowIndex = 3
输出: [1,3,3,1]
示例 2:
输入: rowIndex = 0
输出: [1]
示例 3:
输入: rowIndex = 1
输出: [1,1]
代码:
class Solution:
def getRow(self, rowIndex: int) -> List[int]:
res = [1]
for _ in range(rowIndex):
temp = []
for x in range(1,len(res)):
temp.append(res[x]+res[x-1])
res = [1] + temp + [1]
return res
1338

被折叠的 条评论
为什么被折叠?



