[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, ...
随机推荐
- 如何在 ejs 模板中使用 helper function 外部函数进行特殊处理?
一般我们想要在 ejs 模板中使用外部函数用于特殊的处理,比如:<%= ellipsis(title, 30) %> 通常的做法是: 使用 app.locals 来定义: app.loca ...
- Nginx+Lua 积累
1.解析16进制编码的中文参数 local encodeStr = "%E6%B0%94" local decodeStr = ""; , #encodeStr ...
- 洛谷 P1991 无线通讯网 Label:最小生成树 || 二分
题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的哨所(两边都 ...
- WebBrowser 多线程 DocumentCompleted 和定时器
备忘 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- Application Initialization Module for IIS 7.5
http://www.iis.net/downloads/microsoft/application-initialization IIS7.5也有Warm Up功能 让ASP.NET第一次Reque ...
- 转自:C#中TextBox水印提示的简单实现
本文转自: 原作者: js2854 出处: http://js2854.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...
- ASP.NET中Web DataGrid的使用指南
DataGrid/DataList在ASP.NET非常重要,凡显示Table类型的数据,大多会使用这两个控件. 一.方法 1.DataBind很简单.最常用的方法.绑定数据用.需要注意的只有一点:执行 ...
- iosiPhone屏幕尺寸、分辨率及适配
iosiPhone屏幕尺寸.分辨率及适配 1.iPhone尺寸规格 设备 iPhone 宽 Width 高 Height 对角线 Diagonal 逻辑分辨率(point) Scale Fac ...
- Hirbernate第三次试题分析
解析:HQL语句可以执行T-SQL语句,但执行步骤较复杂,需引入jar包等各种配置. 解析:final修饰的成员变量必须由程序员显式地指定初始值. static一般用于修饰全局变量 解析:Hib ...
- Oracle--数据库中的五种约束
数据库中的五种约束 数据库中的五种约束及其添加方法 五大约束 1.--主键约束(Primay Key Coustraint) 唯一性,非空性 2.--唯一约束 (Unique Counstraint ...