Loading...

10-16 leetcode 0119

链接 119. Pascal’s Triangle II

题意

Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal’s triangle.

In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown:

题解

直接写了

1
2
3
4
5
6
class Solution:
def getRow(self, rowIndex: int) -> list[int]:
row = [1]
for _ in range(rowIndex):
row = [x + y for x, y in zip([0] + row, row + [0])]
return row

Comment