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

Note that the row index starts from 0.

Example:

Input: 3
Output: [1,3,3,1] 

原题地址:Pascal's Triangle II

题意: 杨辉三角

代码: 

class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
res = [1]
for i in range(1, rowIndex+1):
for j in range(i-1, 0, -1):
res[j] = res[j]+res[j-1]
res.append(1)
return res

时间复杂度:O(n^2)

空间复杂度: O(n)

119. Pascal's Triangle II@python的更多相关文章

  1. LeetCode OJ 119. 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, ...

  2. 118/119. Pascal's Triangle/II

    原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...

  3. leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle

    118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...

  4. 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 ...

  5. [LeetCode]题解(python):119 Pascal's Triangle II

    题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...

  6. [LeetCode] 119. Pascal's Triangle II 杨辉三角之二

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

  7. [LeetCode] 119. Pascal's Triangle II 杨辉三角 II

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

  8. LeetCode 119 Pascal's Triangle II

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

  9. leetcode 119 Pascal's Triangle II ----- java

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

随机推荐

  1. java使用Robot类在eclipse上实现自动编写代码

    运行时,把输入法关掉,切换成系统自带的输入法即可: 第二个类是自定义的键值Map集合,主要是为了方便输入字符串,有需要的可以自行添加: 主要的代码如下,会创建一个名称为Automaton.java的类 ...

  2. HTTP2 Sampler for JMeter

    今天开发大大说能不能帮忙压一下HTTP2的链接,便去查了一下相关的东西. HTTP 2.0 的出现,相比于 HTTP 1.x ,大幅度的提升了 web 性能.在与 HTTP/1.1 完全语义兼容的基础 ...

  3. Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A

    Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always bee ...

  4. 跟老男孩学Linx运维---web集群实战笔记

    2018/01/05 2018/01/04 安装:PHP扩展插件PDO_MYSQL-1.0.2报错 In file included from /home/wasadmin/PDO_MYSQL-1.0 ...

  5. Ionic开发-常用命令

      $ionic start myApp [tabs | sidemenu | blank] $ionic platform add android $ionic build android $ion ...

  6. JVM垃圾回收机制四

    GCRoots与可达性分析 Java中的四种引用 强引用.软引用.弱引用.虚引用.这四种引用的强度是逐渐减弱的,JVM垃圾回收的力度是逐渐增强的. 四种引用的作用 1.可以让程序员通过代码来控制对象的 ...

  7. js监听页面的scroll事件,当移到底部时触发事件

    //页面拉到底时自动加载更多 $(window).scroll(function(event){ var wScrollY = window.scrollY; // 当前滚动条位置 var wInne ...

  8. (2017.10.16) javascript 数据类型转换与操作

    javascript 有 5 种基本数据类型:undefined.null.Boolean.String.Number,还有1 种较复杂的数据类型 Object:各种类型之间可以相互转换,其中有些有趣 ...

  9. win7 dos窗口模拟帧刷新

    前几天是白色情人节,临时脑抽写了个表白神器 高端大气上档次,就是不知道该送给谁,经过两天的反射弧思考决定还是写给博客娘吧.- -~ 这个程序就是打开后,在Dos窗口内模拟写出几行字母.其实主要就是模拟 ...

  10. JFinal教程:JFinal极速开发企业实战百集JFinal视频教程发布

    课程名称:JFinal极速开发企业实战 课程长度:100课时 课程作者:小木(909854136) 课程地址:http://edu.csdn.net/course/detail/1968 官网网址:h ...