题目简述:

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?

解题思路:

这里的关键是空间的使用,既然只能用O(K)很容易就想到我们要进行回卷(名字好像不对)。我的做法是每一次都在后面新加入一个数

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

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

  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, Return [1,3 ...

  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】【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, ...

  5. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  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 [1,3 ...

  7. 【LeetCode】731. My Calendar II 解题报告(Python)

    [LeetCode]731. My Calendar II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...

  8. 【LeetCode】137. Single Number II 解题报告(Python)

    [LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...

  9. 【LeetCode】227. Basic Calculator II 解题报告(Python)

    [LeetCode]227. Basic Calculator II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...

随机推荐

  1. Git 总结

    详情请参考:https://git-scm.com/book/zh/v2 注意事项:#1. 多提交(相当于多保存,多^S): 在Git中任何已提交的东西几乎总是可以恢复的. 甚至那些被删除的分支中的提 ...

  2. WordPress酷炫CSS3读者墙代码

    前几日在大前端看到他站点中最新的CSS3读者墙代码,一看效果绚丽的不得鸟,立刻就开始研究了,多次研究未果,可终究是研究出来了,昨天刚成功,今天啊和童鞋来我站说读者墙头像显示不对,我一看,还真是,头像都 ...

  3. 把域名绑定到某个项目,以nginx服务器为例

    一:登陆域名服务器平台,把域名解析到项目对应的IP上面. 二:配置nginx服务器 1./etc/nginx/conf.d/ 在服务器该目录下,添加.conf文件,如命名为:www.demo.com. ...

  4. highcharts去掉版权|去掉水印链接(右下角)_

    credits: {                      enabled: false                  }

  5. mysql 快速简单安装法

    网上下载的编译好的包 最好安装在 /usr/local 目录下面: 我用的mysql的版本的是:mysql--linux-i686-icc-glibc23.tar.gz 在官网上就可以下载到. 先期工 ...

  6. FA模块的10个API范例

    CREATE OR REPLACE PACKAGE BODY cux_fa_do_pkg IS --一.资产新增  PROCEDURE do_addition IS      l_trans_rec  ...

  7. iOS如何彻底避免数组越界

    我们先来看看有可能会出现的数组越界Crash的地方: ? 1 2 3 4 5 6 7 - (void)tableView:(UITableView *)tableView didSelectRowAt ...

  8. phpcurl类

    1.需求 了解curl的基本get和post用法 2.例子 <?php class Curl{ private $timeout=30; public function set_timeout( ...

  9. 微信小程序常见问题集合(长期更新)

    最新更新: 新手跳坑系列:推荐阅读:<二十四>request:fail错误(含https解决方案)(真机预览问题 跳坑指南<七十>如何让微信小程序服务类目审核通过 跳坑六十九: ...

  10. 关于python的10个建议,比较适合新手吧.

    关于python的十个建议 http://safehammad.com/downloads/python-idioms-2014-01-16.pdf