原题地址:https://oj.leetcode.com/problems/pascals-triangle-ii/

题意:

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,
Return [1,3,3,1].

Note:
Could you optimize your algorithm to use only O(k) extra space?

解题思路:思路同上一道题。

class Solution:
# @return a list of integers
def getRow(self, rowIndex):
if rowIndex == 0: return [1]
if rowIndex == 1: return [1, 1]
list = [[] for i in range(rowIndex+1)]
list[0] = [1]
list[1] = [1, 1]
for i in range(2, rowIndex+1):
list[i] = [1 for j in range(i + 1)]
for j in range(1, i):
list[i][j] = list[i - 1][j - 1] + list[i - 1][j]
return list[rowIndex]

[leetcode]Pascal's Triangle II @ Python的更多相关文章

  1. LeetCode Pascal's Triangle && Pascal's Triangle II Python

    Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...

  2. 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4

    当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...

  3. LeetCode: Pascal's Triangle II 解题报告

    Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...

  4. 119. Pascal's Triangle II@python

    Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...

  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 - Pascal's Triangle II

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

  7. LeetCode——Pascal's Triangle II

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

  8. leetcode:Pascal's Triangle II【Python版】

    1.将tri初始化为[1],当rowIndex=0时,return的结果是:1,而题目要求应该是:[1],故将tri初始化为[[1]],返回结果设置为tri[0]即可满足要求: 2.最开始第二层循环是 ...

  9. leetcode:Pascal's Triangle【Python版】

    1.这道题一次提交就AC了: 2.以前用C语言实现的话,初始化二维数组全部为0,然后每行第一个元素为1,只需要用a[i][j] = a[i-1][j]+a[i-1][j-1]就可以了: 3.在Pyth ...

随机推荐

  1. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

  2. hdu 5781 ATM Mechine dp

    ATM Mechine 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...

  3. rsync使用sudo权限

    1.在etc/sudoers增加,比如www-data这个账户的 www-data ALL=NOPASSWD:/usr/bin/rsync 2.使用时增加--rsync-path="sudo ...

  4. 华为S5300系列交换机限制特定IP可以登录Web

    针对Web管理可能有如下需求: 1.限制某个特定IP允许访问Web 2.默认修改80端口访问 那么针对上面的设置可以有效杜绝而已Web密码暴力破解,增强交换机安全等. 实现: 1.限制特定IP登录We ...

  5. 一种高效的序列化方式——MessagePack

    最近在弄一些数据分析方面的内容,发现很多时候数据瓶颈在模块之间的数据序列化和反序列化上了,原来项目中用的是Json,找了一圈发现Json.net在Json序列化库中已经是性能的佼佼者了,便准备从序列化 ...

  6. STM32F2x Is it possible to request multiple DMA streams with single request

    I want to setup an application, where a single trigger-factor (compare-match of a timer) shall reque ...

  7. CRC 详解

    http://www.barrgroup.com/Embedded-Systems/How-To/Additive-Checksums CRC Series, Part 1: Additive Che ...

  8. .NET基于Eleasticsearch搭建日志系统实战演练

    一.需求背景介绍 1.1.需求描述 大家都知道C/S架构模式的客户端应用程序(比如:WinForm桌面应用.WPF.移动App应用程序.控制台应用程序.Windows服务等等)的日志记录都存储在本地客 ...

  9. delphi 取上级目录

    var  S: string;begin  S := 'c:\aa\bb\cc\dd\abc.exe';  ShowMessage(ExtractFileDir(ExtractFileDir(S))) ...

  10. python脚本从excel表到处数据,生成指定格式的文件

    #coding:gbk #导入处理excel的模块 import xlrd #定义哪些字段须要推断,仅仅支持时间字段 toSureColArray = ['CREATE_TIME','MODIFY_T ...