[LeetCode]题解(python):119 Pascal's Triangle II
题目来源
https://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].
题意分析
Input:integer
Output:kth row of the Pascal's triangle
Conditions:只返回第n行
题目思路
同118,不同之处在于只返回某一层,同时注意与上题的下标起点不一样(rowIndex先加个1 = =)
AC代码(Python)
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
rowIndex += 1
ans = []
if rowIndex == 0:
return []
for i in range(rowIndex):
this = []
for j in range(i+1):
this.append(1)
if i > 1:
for x in range(i - 1):
this[x+1] = ans[i-1][x] + ans[i-1][x+1]
print this
ans.append(this) return ans[rowIndex - 1]
[LeetCode]题解(python):119 Pascal's Triangle II的更多相关文章
- LeetCode Array Easy 119. Pascal's Triangle II
Description Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's tria ...
- 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- ...
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- 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, ...
- 118/119. Pascal's Triangle/II
原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...
- 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 ...
- [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 ...
- [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, ...
- LeetCode 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, ...
随机推荐
- sqlserver中创建链接服务器
链接服务器在跨数据库/跨服务器查询时非常有用(比如分布式数据库系统中),本文将以图文方式详细说明如何利用SQL Server Management Studio在图形界面下创建链接服务器. 1 ...
- CF#335 Lazy Student
Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CentOS6.4 安装SSDB
1.安装 wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zipunzip mastercd ssd ...
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...
- 【BZOJ2438】 [中山市选2011]杀人游戏 tarjan强连通分量+缩点
Description 一位冷血的杀手潜入 Na-wiat,并假装成平民.警察希望能在 N 个人里面,查出谁是杀手. 警察能够对每一个人进行查证,假如查证的对象是平民,他会告诉警察,他认识的人, 谁是 ...
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- 全浏览器收藏网站javascript
function MyFavorite(sURL, sTitle) { var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != ...
- servlet session 相关
1.session是server维护的一个变量,如果消除每个session?----这里只做指定key的session删除 1.1.显示调用 废除指定key的session session.remov ...
- getElementsByClassName的兼容性
/*----------------------------index.html------------------------------------*/ <!DOCTYPE html> ...
- java代码实现打包多个文件下载功能
//传入对应的需要打包的file 集合对象 //文件打包下载 public static HttpServletResponse downLoadFiles(List<File> ...