• 【leetcode】Pascal's Triangle


    题目简述:

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

    解题思路:

    很简单的问题,只要把两头的一拿出来,中间就是两个数相加了。

    class Solution:
        # @return a list of lists of integers
        def generate(self, numRows):
            if numRows == 0:
                return []
            res = [[1]]
            for i in range(1,numRows):
                t = [1]
                pre = res[-1]
                for i in range(len(pre)-1):
                    t.append(pre[i]+pre[i+1])
                t.append(1)
                res.append(t)
            return res
  • 相关阅读:
    第几天?
    农历02__资料
    农历01
    VC6_预编译头
    QWebEngine_C++_交互
    Qt570_CentOS64x64_02
    Qt570_CentOS64x64_01
    QWebEngineView_CssVariables
    Windows__书
    Win7SDK
  • 原文地址:https://www.cnblogs.com/MrLJC/p/4369811.html
Copyright © 2020-2023  润新知