【Leetcode】Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's tri...

Given a non-negative index kwhere k ≤ 33, return the kthindex row of the Pascal's triangle.

Note that the row index starts from 0.

class Solution(object):

    def getRow(self, rowIndex):

        """

        :type rowIndex: int

        :rtype: List[int]

        """

        row = [1]

        for index in range(1, rowIndex+1):

            row = [1]+[row[x]+row[x-1] for x in range(1, index)] + [1]

        return row

1 list可以用[]相互加起来

你可能感兴趣的:(【Leetcode】Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's tri...)