#-*- 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. 9. 星际争霸之php设计模式--代理模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  2. [Ubuntu] Autostart nginx, php-fpm and mysql in Ubuntu14.04

    [nginx] Step 1 Download the shell script wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu ...

  3. 给图像添加logo

    #include <opencv2\opencv.hpp>#include"ProcessPixels.h"using namespace cv;using names ...

  4. 【DP水题】投票问题(二)

    投票问题(一) [试题描述] 欧阳文和欧阳武竞选学联主席,汪梁森负责唱票,共有m+n张,结果欧阳文获胜,已知欧阳文和欧阳武分别获得 m 张票和 n 张票(m>n).现在请你计算在唱票过程中欧阳文 ...

  5. 在线快速生成 CSS Sptite 的网站

    Spritepad http://spritepad.wearekiss.com/ 这个好,虽然没用过,先收起来再说.

  6. React笔记_(4)_react语法3

    生命周期 很多语言中都讲了关于生命周期.这可是决定生命的周始,有没有存在感的关键啊. 生命周期,有生有死,有始有终,因果轮回,循环往复.(说多了) react中,主要说明的是 一个组件的生命周期.简单 ...

  7. HTTP详解(1)-工作原理【转】

    转自:http://blog.csdn.net/hguisu/article/details/8680808 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] 1 HTTP简 ...

  8. IOS中用UIStoryBoard类初始化/跳转控制器

    1.空工程中通过创建storyboard文件加载页面   //获取Main.storyboardUIStoryboard *mainStory = [UIStoryboard storyboardWi ...

  9. HDU 4417:Super Mario(主席树)

    http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意是:给出n个数和q个询问,每个询问有一个l,r,h,问在[l,r]这个区间里面有多少个数是小于等于h的 ...

  10. [HTML]表格的一切

    如何设置HTML页面自适应宽度的table(表格): <table width="95%" border="1" cellpadding="2& ...