Skip to content

119 Pascal's Triangle II

119. Pascal's Triangle II

题目: https://leetcode.com/problems/pascals-triangle-ii/

难度 : Easy

思路:

太简单了,注意一点算数就好

class Solution(object):
    def getRow(self, rowIndex):
        """
        :type rowIndex: int
        :rtype: List[int]
        """
        if rowIndex == 0:
            return [1]
        res = [1]
        for i in range(1, rowIndex+1):
            tmp = [1]
            for j in range(1, i):
                tmp.append(res[j-1]+res[j])
            tmp.append(1)
            res = tmp
        return res


回到顶部