Pascal's Triangle

    xiaoxiao2021-03-25  97

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

    自己没有想到很好的解法,看了solution,被其代码惊呆了,写的很好。

    class Solution(object): def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ if numRows == 0: return [] res = [[1]] for i in range(1, numRows): res += [map(lambda x, y: x+y, res[-1] + [0], [0] + res[-1])] return res
    转载请注明原文地址: https://ju.6miu.com/read-16383.html

    最新回复(0)