#-*- 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的更多相关文章

  1. 【leetcode❤python】119. Pascal's Triangle II

    #-*- coding: UTF-8 -*-#杨辉三角返回给定行#方法:自上而下考虑问题,从给定的一行计算出下一行,则给定行数之后,计算的最后一行就是求解的最后一行class Solution(obj ...

  2. [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 ...

  3. 【LeetCode】118. Pascal's Triangle 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  4. 【一天一道LeetCode】#118. Pascal's Triangle

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...

  5. 【LeetCode】118. Pascal's Triangle

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...

  6. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  7. LeetCode Array Easy 118. Pascal's Triangle

    Description Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. I ...

  8. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  9. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

随机推荐

  1. C# 控制台程序如何防止启动多个实例

    ==================================================================================================== ...

  2. css样式重写

    //我们经常想修改插件的某一个或几个样式特性,并保留其它的样式.而不是把某个css全部重写一遍. /*原有样式*/.ninew {padding: 0 10px;width: 600px;height ...

  3. Android—监听器

    网上有很多短信和电话监听的程序,使用Broadcast. 记得一年前自己对照视频和教材是能够实现的,这周打开视频和教材照猫画虎,无论怎么都不会,纠结啊! 问题原因: 3.0之后没有主动开启过的应用无法 ...

  4. keep your work after network broken

    如下设置可以保证在网络中断后tso仍然可以继续active,并等到下一次reconnect sys1.tcpparms(tnprof7d) -- Dataset name and PDS name b ...

  5. Android SDK Manager更新报错

    错误log: Fetching https://dl-ssl.google.com/android/repository/addons_list-.xml Fetched Add-ons List s ...

  6. Java throw:异常的抛出怎么回事

    到目前为止,你只是获取了被Java运行时系统抛出的异常.然而,程序可以用throw语句抛出明确的异常.Throw语句的通常形式如下:    throw ThrowableInstance;这里,Thr ...

  7. UINavigationController(转)

    UINavigationController是IOS编程中比较常用的一种容器view controller,很多系统的控件(如UIImagePickerViewController)以及很多有名的AP ...

  8. RAII惯用法详解

    [1]什么是RAII惯用法? RAII是Resource Acquisition Is Initialization的缩写,意为“资源获取即初始化”. 它是C++之父Bjarne Stroustrup ...

  9. Linux系统的中断、系统调用和调度概述【转】

    转自:http://blog.csdn.net/yanlinwang/article/details/8169725 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近学习Linux操作系统, ...

  10. Web SQL

    HTML5本地存储——Web SQL Database 基于 HTML5 中的 Web SQL Database 来构建应用程序 前端HTML5几种存储方式的总结 <!DOCTYPE HTML& ...