【leetcode❤python】119. Pascal's Triangle II
#-*- coding: UTF-8 -*-
#杨辉三角返回给定行
#方法:自上而下考虑问题,从给定的一行计算出下一行,则给定行数之后,计算的最后一行就是求解的最后一行
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
#初始化杨辉三角前两行
ans=[[1],[1,1]]
#如果输入rowIndex小于2 表示的是前两行
if rowIndex<2:return ans[rowIndex]
#以初始化的杨辉三角为第一个一个pre=ans[-1]
pre=ans[-1]
#i表示的是从第一行开始计算一直计算到rowIndex-1行,i=1可以计算出i=2
for i in range(1,rowIndex):
print i, pre
# t 表示计算的是下一行元素的 除去首尾两个的其他元素值
nextT=[1]+[pre[t]+pre[t+1] for t in range(len(pre)-1)]+[1]
pre=nextT
return pre
【leetcode❤python】119. Pascal's Triangle II的更多相关文章
- 【leetcode❤python】118. Pascal's Triangle
#-*- coding: UTF-8 -*-#杨辉三角class Solution(object): def generate(self, numRows): "&quo ...
- 【一天一道LeetCode】#119. Pascal's Triangle II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【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 [ ...
- 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 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, ...
- 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- ...
- 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]题解(python):119 Pascal's Triangle II
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...
随机推荐
- Hibernate开始上手总结
1,导入hibernate 的jar包,c3p0jar包 2,创建和表关联的实体类,创建关联实体类的配置文件 package com.entity; public class News { priva ...
- 夺命雷公狗---node.js---16之项目的构建在node+express+mongo的博客项目1
废话不多说我们直接开工... 直接在目录下打开黑窗口: 然后就开始看看我们创建出来的文件了: 然后就开始创建项目下的目录了: 从这里就可以清晰的看得到我们的目录都是以前后台来分离开来的,引入模版也很简 ...
- nginx在windwos中的使用
本文章参考了 nginx for windows的介绍:http://nginx.org/en/docs/windows.html 你从官网上下载到的是一个 zip 格式的压缩包,首先要把压缩包解压. ...
- 白盒测试的学习之路----(五)TestNG的参数分离
之前的测试用例直接嵌套在代码中,不便于维护和测试设计,应该单独把测试用例放在excel内,然后程序从中读取数据到相应的接口内即可.使用ava程序对Microsoft Office格式档案读和写的功能提 ...
- ubuntu SVN环境配置(转)
一.SVN安装1.安装包$ sudo apt-get install subversion 2.添加svn管理用户及subversion组$ sudo adduser svnuser$ sudo ad ...
- Openstack的dashboard开发之【浏览器兼容性】
完全不支持浏览器: ie9(含)以下ie低版本浏览器及使用ie低版本浏览器的内核的扩展浏览器,如360安全浏览器(内核ie6) 原因:不支持vnc(需要浏览器支持才有vnc功能),jquery也不在支 ...
- oracle sql语言模糊查询--通配符like的使用教程
转自:http://www.cnblogs.com/tyler2000/archive/2011/04/28/oracleSql.html oracle在Where子句中,可以对datetime.ch ...
- minio-dotnet --云存储服务
inio是一家成立于2014年的生产开源云存储产品的新兴创业公司.这家创业公司是其创始人继Gluester之后的又一杰作,Gluester公司已经在2011年被Red Hat公司以1.36亿美元的价格 ...
- db2常用函数(1)
VALUE函数 语法:VALUE(EXPRESSION1,EXPRESSION2) VALUE函数是用返回一个非空的值,当其第一个参数非空,直接返回该参数的值,如果第一个参数为空,则返回第一个参数的值 ...
- mysql 段错误 (core dumped)
一直使用好好的mysql命令,突然今天抽风,无论使用任何mysql选项都报“段错误 (core dumped)”,以为是mysqld程序出问题了,所以我尝试重启,因为我的环境上是多实例,用了mysql ...