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)
                   

  • 相关阅读:
    vue_03
    vue03
    vue2
    vue02
    vue 01
    JavaScript要点 (一) 变量-作用域
    在iOS应用程序中打开设备设置界面及其中某指定的选项界面
    多线程操作Coredata(转)
    iOS_城市定位
    本地验证码
  • 原文地址:https://www.cnblogs.com/kwangeline/p/5953484.html
Copyright © 2011-2022 走看看