zoukankan      html  css  js  c++  java
  • 【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)
                   

  • 相关阅读:
    python中break与continue区别
    jmeter正则表达式
    python的input()函数与getpass标准库
    python实例练习-01登录
    python数据类型-字符串
    jmeter操作mysql
    jmeter文件下载
    字符逆序
    求解立方根
    求最小公倍数
  • 原文地址:https://www.cnblogs.com/kwangeline/p/5953484.html
Copyright © 2011-2022 走看看