美文网首页
#119. Pascal's Triangle II

#119. Pascal's Triangle II

作者: Double_E | 来源:发表于2017-03-25 20:07 被阅读6次

    Python

    for example
    let L=rowIndex + 1
    1, 1, 1, 1
    So L=4, let i = range(1, L) and j=range(1, i)
    i = 1, j = range(1, 1) 不运行
    i = 2, j = 1
    1, 2, 1, 1
    i = 3, j = 1
    1, 2, 3, 1 ... 1 = 1 + 2
    i = 3, j = 2
    1, 3, 3, 1 ... 2 = 1+2

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

    相关文章

      网友评论

          本文标题:#119. Pascal's Triangle II

          本文链接:https://www.haomeiwen.com/subject/bpncottx.html