<LeetCode><Easy> 118 Pascal's Triangle

来源:互联网 发布:国际机票 知乎 编辑:程序博客网 时间:2024/05/17 08:43

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]]

Show Tags
Show Similar Problems



#Python2 40ms  递归
class Solution(object):    def generate(self, numRows):        """        :type numRows: int        :rtype: List[List[int]]        """        if not numRows:return []        if numRows==1:return [[1]]        i,rows=1,[[1],]        while i<numRows:            i+=1            rows.append(map(lambda a,b:a+b,[0]+rows[-1],rows[-1]+[0]))        return rows


0 0
原创粉丝点击