题目: 给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex行。 在「杨辉三角」中,每个数是它左上方和右上方的数的和。 来源:力扣(LeetCode) 链接:力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台 示例: 示例 1: 输入:rowIndex = 3 输出:[1,3,3,1] 示例 2: 输入:rowIndex = 0 输出:[1] 示例 3: 输入:rowIndex = 1 输出:[1,1] 解法: 第i行=第i-1行左添0+右添0得到。 代码: python 复制代码 class Solution: def getRow(self, rowIndex: int) -> List[int]: n = [1] for _ in range(rowIndex + 1): result = n n = [x + y for x, y in zip([0] + n, n + [0])] return result
给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex行。
rowIndex
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
来源:力扣(LeetCode)
链接:力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台
示例 1:
输入:rowIndex = 3
输出:[1,3,3,1]
示例 2:
输入:rowIndex = 0
输出:[1]
示例 3:
输入:rowIndex = 1
输出:[1,1]
第i行=第i-1行左添0+右添0得到。
class Solution: def getRow(self, rowIndex: int) -> List[int]: n = [1] for _ in range(rowIndex + 1): result = n n = [x + y for x, y in zip([0] + n, n + [0])] return result