题目简述:

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

【leetcode】Pascal's Triangle的更多相关文章

  1. 【LeetCode】Pascal's Triangle II 解题报告

    [LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...

  2. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  3. 【leetcode】Pascal's Triangle I & II (middle)

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  4. 【LeetCode】Pascal's Triangle II (杨辉三角)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  5. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. 【Leetcode】【Easy】Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  7. 【Leetcode】【Easy】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  8. 【LeetCode】611. Valid Triangle Number 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/valid-tri ...

  9. 【LeetCode】812. Largest Triangle Area 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 三重循环 组合函数 日期 题目地址:https:// ...

随机推荐

  1. webapi-创建项目

  2. 【译】使用 CocoaPods 模块化iOS应用

    原文翻译自:Using CocoaPods to Modularize a Big iOS App 为你的移动应用选择正确的架构是一件相当大的事情,这会对你的工作流程造成影响,陷入面对的问题,可能是一 ...

  3. Fedora20-32bit cross-compiling arm-linux-gcc4.3.2

    目录 0 前言 1 安装arm-linux-gcc-4.3.2 2 配置 nfs 服务器 0 前言 之前在 fedora 64bit 上建立交叉编译,但由于4.4.3版本需要另装用于gdb-serve ...

  4. js自动轮播图片的两种循环方法(原创)

    用5个div,布局从左到右5张图片,从左到右5个div分别指定ID为img1,img2,img3,img4,img5.(背景是relative,5个div是相对于背景absolute定位) 显示如下: ...

  5. SqlDataReader和SqlDataAdapter

    SqlDataReader 高效,功能弱,只读访问SqlDataAdapter 强大,要求资源也大一点 SqlDataReader 只能在保持跟数据库连接的状态下才可以读取... SqlDataAda ...

  6. 内核编译报错Fedora20(友善)

    首先说明我的宿主机环境:Fedora20 64位,开发板是友善Smart210(S5PV210——Cotex-A8)!!!马上入题! 按照开发板的用户手册来编译内核,一直报这个错误:/opt/Frie ...

  7. pycharm快捷键及一些常用设置

    pycharm快捷键及一些常用设置,有需要的朋友可以参考下. Alt+Enter 自动添加包 Ctrl+t SVN更新 Ctrl+k SVN提交 Ctrl + / 注释(取消注释)选择的行 Ctrl+ ...

  8. Linux(Ubuntu)下安装NodeJs

    用以下命令来升级系统,并且安装一些Node.JS必要的包. Linux(Ubuntu)下安装NodeJs 安装nodeJS之前,如果没有安装g++ make libssl-dev等, 1.更新系统和依 ...

  9. 已安装php 编译安装 gd库拓展模块

    参考资料:http://wenku.baidu.com/link?url=EgXFShYxeJOZSYNQ_7RCBC-6X8OcRRCqVm4qCv49uBk57d6vLBoUpfYdQ-KqJRs ...

  10. XUT 1245

    这是一道2016湘潭邀请赛的题目,记得那个时候看到这个题目就想到了最短生成树,然后给别人做,WA了,最后发现是有向图,然后我自己去写了个搜索,结果是RE吧 今天刚刚好想到这个题目,然后再来做,发现这个 ...