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)
                   

  • 相关阅读:
    Spring Batch与ETL工具比较
    Spring Batch基本概念
    SpringBatch介绍
    2019第51周日
    用arthas的watch方法观察执行方法的输入输出
    三人行必有我师
    用arthas查看JVM已加载的类及方法信息
    线上问题排查利器Arthas
    换个视觉
    Java Servlet:服务器小程序
  • 原文地址:https://www.cnblogs.com/kwangeline/p/5953484.html
Copyright © 2011-2022 走看看