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. GridSearchCV.grid_scores_和mean_validation_score报错

    目录 GridSearchCV.grid_scores_和mean_validation_score报错 0. 写在前面 1. 问题描述和解决过程 2. 不想比比直接看结果部分 GridSearchC ...

  2. Nacos深入浅出(七)

    大家可以把这个也下载下来,结合之前的Nacos一起来看下,感觉前面几篇看了好像冰山一角的感觉 学无止境! https://github.com/nacos-group/nacos-spring-pro ...

  3. GZS与小公园(DFS)

    Description 某天GZS漫步在学校新建的小公园,他发现那里建成了一些水池和小河道.我们暂且把它们统一看成水池.假设公园旁有一张小公园的地图,上面仅标识了此处是否是水池,你能帮GZS计算出该地 ...

  4. echart option属性

    option 图表选项,包含图表实例任何可配置选项: 公共选项 , 组件选项 , 数据选项 名称 描述 {color}backgroundColor 全图默认背景,(详见backgroundColor ...

  5. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B

    Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a,  ...

  6. 练习三十二:用python实现:按相反的顺序输出列表的每一位值

    用python实现:按相反的顺序输出列表的每一位值 1. 使用list[::-1] list1 = ["one","two","three" ...

  7. NET Core中使用Redis和Memcached

    .NET Core中使用Redis和Memcached的序列化问题   前言 在使用分布式缓存的时候,都不可避免的要做这样一步操作,将数据序列化后再存储到缓存中去. 序列化这一操作,或许是显式的,或许 ...

  8. java课后思考问题(七)

    1.继承条件下的构造方法调用 package parent;class Grandparent { public Grandparent() { System.out.println("Gr ...

  9. Nuxt使用记录

    代码及插件需要根据环境引入 (服务端没有window,document,浏览器端没有global) const myPlugins = { install(Vue, options) { Vue.pr ...

  10. HangFire 定时任务

    https://www.cnblogs.com/ecin/p/6201262.html#%E5%9F%BA%E4%BA%8E%E9%98%9F%E5%88%97%E7%9A%84%E4%BB%BB%E ...