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.app

Note that the row index starts from 0.spa

Example:code

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

原題地址: Pascal's Triangle IIblog

題意: 楊輝三角ip

代碼: leetcode

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)get

空間複雜度: O(n)io

相關文章
相關標籤/搜索