码迷,mamicode.com
首页 > 编程语言 > 详细

119. Pascal's Triangle II@python

时间:2018-10-05 17:21:25      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:amp   scals   def   targe   pascal   strong   HERE   lis   als   

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

标签:amp   scals   def   targe   pascal   strong   HERE   lis   als   

原文地址:https://www.cnblogs.com/chimpan/p/9745098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!