#-*- 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. js 去除空格

    var MAX_PERIOD = $('#MAX_PERIOD').val(); // 借款的最大期限 MAX_PERIOD=Trim(MAX_PERIOD,"g");   //带 ...

  2. Linux 安装 nginx注意

    ./configure --prefix=/usr/local/nginx TO ./configure --prefix=/usr/local/nginx --conf-path=/usr/loca ...

  3. AR 应收 表

    AR 应收 应收事务处理相关表 SELECT * FROM ar.ar_batches_all;                  --事务处理批 SELECT * FROM ar.ra_custom ...

  4. Java如何对ArrayList里的元素排序

  5. android 项目学习随笔十一(ListView下拉刷新提示)

    1. 设置mHeaderView.setPadding TOPPADING为负值,隐藏刷新提示头布局 在onTouchEvent事件中进行头布局显示隐藏切换 import java.text.Simp ...

  6. autohotkey-【GUI】Switch between Windows of the Same Application

    下面给出了ahk的脚本,但我需要GUI http://superuser.com/questions/435602/shortcut-in-windows-7-to-switch-between-sa ...

  7. 使用 ViewPager 和 RadioGroup 封装的一个导航控件

    import android.animation.ObjectAnimator; import android.content.Context; import android.graphics.dra ...

  8. Zero_qiqi DIV模式的省市区三级联动

    1].[代码] [HTML]代码 跳至 [1] [2] [3] [4] [5] [6] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...

  9. Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)

    MD5和RSA是网络传输中最常用的两个算法,了解这两个算法原理后就能大致知道加密是怎么一回事了.但这两种算法使用环境有差异,刚好互补. 一.MD5算法 首先MD5是不可逆的,只能加密而不能解密.比如明 ...

  10. [算法][包围盒]球,AABB,OBB

    参考地址请看图片水印:http://www.cnblogs.com/iamzhanglei/archive/2012/06/07/2539751.html http://blog.sina.com.c ...