【leetcode❤python】118. Pascal's Triangle
#-*- coding: UTF-8 -*-
#杨辉三角
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
result=[];row=1
while True:
tmplist=[1]*row
i=0;flag=0
while True:
if i==0:
tmplist[0]=1;tmplist[row-1]=1
flag+=2
else:
tmplist[i]=result[row-2][i-1]+result[row-2][i]
tmplist[row-i-1]=tmplist[i]
flag+=2
i+=1
if flag>=row:break
result.append(tmplist)
row+=1
if row>numRows:break
return result
sol=Solution()
print sol.generate(1)
【leetcode❤python】118. Pascal's Triangle的更多相关文章
- 【leetcode❤python】119. Pascal's Triangle II
#-*- coding: UTF-8 -*-#杨辉三角返回给定行#方法:自上而下考虑问题,从给定的一行计算出下一行,则给定行数之后,计算的最后一行就是求解的最后一行class Solution(obj ...
- [LeetCode&Python] Problem 118. Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...
- 【LeetCode】118. Pascal's Triangle 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- 【一天一道LeetCode】#118. Pascal's Triangle
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...
- 【LeetCode】118. Pascal's Triangle
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- LeetCode Array Easy 118. Pascal's Triangle
Description Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. I ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
随机推荐
- notepad++ 行末尾添加指定字符
在查找目标中输入“^”代表行首,“$”代表行末,下方的查找模式要改成“正则表达式”. 如果替换中有字符,则用“\”转义, 例如 : 目标中输入: $ 替换字符输入: \, 则是每行后面加 ...
- 广告点击率 CTR预估中GBDT与LR融合方案
http://www.cbdio.com/BigData/2015-08/27/content_3750170.htm 1.背景 CTR预估,广告点击率(Click-Through Rate Pred ...
- MyEclipse 死掉,JVM terminated. Exit code=1073807364
刚入手的新成员,刚开始使用myeclipse,是不是会有一大堆的问题,然后没有目标的走,这里有个小技巧,那就是如果做项目出现问题,一定要自己现在网络搜寻答案,网络时代.技术时代走到现在,一定有他的道理 ...
- linux与windows的文本文件之间的转换
在CentOS中需要安装一个软件包:tofrodos 包里包含的命令可以用包管理工具列出包里的文件. 以 CentOS 的 rpm 为例: rpm -ql tofrodos 在ArchLinux中需要 ...
- Javascript Regexp match and replace
# add a new article reference to database function addnewpub() { var year = $("input#year" ...
- 11、Jsp加强/EL表达式/jsp标签
1 Jsp基础回顾 Jsp基础 1)Jsp的执行过程 tomcat服务器完成:jsp文件->翻译成java文件->编译成class字节码文件-> 构造类对象-> 调用方法 to ...
- WPF:获取控件内的子项
一.界面内容(部分:仅供参考) <Window> <Window.Resources> <!--工具数据源--> <XmlDataProvider x:Key ...
- C#:通过Window API接口实现WiFi
1.获取Mac地址 //WiFi通知回调 private WlanApi.WLAN_NOTIFICATION_CALLBACK _notificationCallback; this._notific ...
- ecshop后台增加模板页的方法
CShop的动态模板机制是一个非常灵活的系统,管理员可以在后台根据自己的要求调整模板模块的显示位置.本文详细讲解了如何修改ECSHOP内部结构使得用户可以添加自己的模板页从而方便灵活的使用系统自带的模 ...
- oracle 执行执行动态存储过程名---其实就是存储过程名是个字符串参数
假设我有一个过程P1(V1 IN VARCHAR2),另一有一个过程EX(P IN VARCHAR2,P IN VARCHAR2),第一个参数是过程名,第二个参数是指定过程的参数,我执行EX('P1' ...