【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): ...
随机推荐
- 《zw版·Halcon-delphi系列原创教程》 2d照片-3d逆向建模脚本
<zw版·Halcon-delphi系列原创教程> 2d照片-3d逆向建模脚本 3D逆向建模,是逆向工程的核心要素. 3D逆向建模,除了目前通用的3D点云模式,通过2D图像实现 ...
- JavaScript的函数和事件(转)
一.默认函数 JavaScript提供了一些默认的函数 编码函数escape():将非字母.数字字符转换成ASCII码 译码函数unescape():将ASCII码转换成字母.数字字符 求值函数eva ...
- equals和==
在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str2 = new String(&qu ...
- iOS的第一个习作
首发:个人博客,更新&纠错&回复 代码在这里,对git还是使用不熟练,好在github新建项目后体贴地提示是不是要执行这样两句—— 这两句我肯定是背不住的,所以记一下. git rem ...
- 小结 javascript中的类型检测
先吐槽一下博客园的编辑器,太不好用了,一旦粘贴个表格进来就会卡死,每次都要用html编辑器写,不爽! 关于javascript的类型检测,早在实习的时候就应该总结,一直拖到现在,当时因为这个问题还出了 ...
- JAVA 集合List,数组,Set,Map,直接的相互转换
Java集合转换[List<-->数组.List<-->Set.数组<-->Set.Map-->Set.Map-->List] //List--> ...
- windows prompt personalize 设置cmd提示的相关
由于有一篇随笔种我说要引用这篇文章,所以不得已也出来了,就像你说大话『我明天去吃屎』,结果你做到了. 我这记录一下有关windows prompt这是的变量,我不知道这算不算变量,因为windows变 ...
- linux下用core和gdb查询出现"段错误"的地方【转】
转自:http://blog.chinaunix.net/uid-30091091-id-5754288.html 原文地址:linux下用core和gdb查询出现"段错误"的地方 ...
- Mootools插件-闪烁的标题
转自:http://www.cnblogs.com/see7di/archive/2012/10/09/2716024.html 回想起来,我已经好久没有写点啥了,尤其是关于Mootools方面的东西 ...
- SQL中char、varchar、nvarchar的区别
char char是定长的,也就是当你输入的字符小于你指定的数目时,char(8),你输入的字符小于8时,它会再后面补空值.当你输入的字符大于指定的数时,它会截取超出的字符. nvarcha ...