119. Pascal's Triangle II*

原创 2016年08月31日 16:27:20

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,
Return [1,3,3,1].

Note:
Could you optimize your algorithm to use only O(k) extra space?

Reference

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

Note:

It is obvious that we should find the law of numbers in certain row of Pascal's Triangle.

According to materials online, the nth number in mth row is C(m,n-1).However, this method needs a lot of computation.

版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode 119. Pascal's Triangle II

题目: Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return...

LeetCode119 Pascal's Triangle II

详细见:leetcode.com/problems/pascals-triangle-ii Java Solution: github package leetcode; impor...
  • zxwtry
  • zxwtry
  • 2017年05月04日 22:23
  • 222

[LeetCode-119] Pascal's Triangle II(帕斯卡三角形第K行数据)

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,...

119. Pascal's Triangle II

问题描述: Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Retu...
  • yyg_wtf
  • yyg_wtf
  • 2016年04月21日 10:43
  • 200

118、119 pascal's triangle I、II---Array-LeetCode

118 pascal's triangle I---Array-LeetCode 找规律 a = b + c。 119 pascal's triangle II---Array-LeetCode ...

LeetCode - 119. Pascal's Triangle II

这道题目与118. Pascal's Triangle很像,所不同的是这道题要求的是打印出制定某行,而上一题则是将所有的全都打印出来。一个非常简单的想法自然是先计算出整个三角形,然后再打印出某个指定的...

LeetCode笔记:119. Pascal's Triangle II

计算杨辉三角形特定行的内容

<LeetCode OJ> 118 / 119 Pascal's Triangle(I / II)

118. Pascal's Triangle My Submissions Question Total Accepted: 73965 Total Submissions: 227957 D...

LeetCode: Pascal's Triangle II [119]

【题目】 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retu...

[119] Pascal's Triangle II

给定一个数值n,返回杨辉三角中的第n行元素。
  • camlot_
  • camlot_
  • 2016年07月19日 20:38
  • 188
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:119. Pascal's Triangle II*
举报原因:
原因补充:

(最多只允许输入30个字)