美文网首页
#118. Pascal's Triangle

#118. Pascal's Triangle

作者: Double_E | 来源:发表于2017-03-25 19:30 被阅读17次

    Given numRows, generate the first numRows of Pascal's triangle.
    For example, given numRows = 5,Return
    [ [1],
    [1,1],
    [1,2,1],
    [1,3,3,1],
    [1,4,6,4,1]]
    Subscribe to see which companies asked this question

    Python

    class Solution(object):
        def generate(self, numRows):
            """
            :type numRows: int
            :rtype: List[List[int]]
            """
            x = []
            for i in range(numRows):
                t = [1] * (i + 1)
                x.append(t)
                for j in range(1, i):
                    x[i][j] = x[i-1][j-1] + x[i-1][j]
            return x
    
            
    

    相关文章

      网友评论

          本文标题:#118. Pascal's Triangle

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