119. Pascal's Triangle II@python

Posted Chim

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了119. Pascal's Triangle II@python相关的知识,希望对你有一定的参考价值。

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal‘s triangle.

Note that the row index starts from 0.

Example:

Input: 3
Output: [1,3,3,1] 

原题地址: Pascal‘s Triangle II

题意: 杨辉三角

代码: 

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

时间复杂度:O(n^2)

空间复杂度: O(n)

 

以上是关于119. Pascal's Triangle II@python的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode_119. Pascal's Triangle II

119. Pascal's Triangle II

119. Pascal's Triangle II@python

119. Pascal's Triangle II

119. Pascal's Triangle II

119. Pascal's Triangle II