【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,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的更多相关文章
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- 【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 ...
- 【leetcode】Pascal's Triangle I & II (middle)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【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, ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 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 ...
- 【LeetCode】731. My Calendar II 解题报告(Python)
[LeetCode]731. My Calendar II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】227. Basic Calculator II 解题报告(Python)
[LeetCode]227. Basic Calculator II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
随机推荐
- Dubbo项目demo搭建
项目参考: http://dubbo.io/User+Guide-zh.htm https://my.oschina.net/superman158/blog/466637 项目使用 maven+id ...
- 8Spring初步----青软S2SH(笔记)
例子: bean.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...
- R自动数据收集第二章HTML笔记2(主要关于htmlTreeParse函数)
包含以下几个小的知识点 1htmlTreeParse函数源码和一些参数 2hander的写法 3关于missing函数 4关于if-else语句中else语句的花括号问题 5关于checkHandle ...
- HDU 1859
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> ...
- SQL Server数据库定时自动备份
SQL Server 数据库定时自动备份[转] 在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求 ...
- AVPlayer
AVPlayer AVPlayerLayer是CALayer的一个子类,由于AVPlayer这个播放器只能安置在AVPlayerLayer 这个图层之上,所以我们需要实例化一个UIView,并 ...
- bzoj1492 斜率优化|cdq分治
#include <stdio.h> #include <bitset> #include <string.h> #include <stack> #i ...
- js 判断客户端浏览器
var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { ...
- js array push 添加内容
向数组中天机内容: var array = new Array(); array.push('newItem');
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...