mycode   16.47%

class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if not numRows : return []
elif numRows == 1 : return [[1]]
res = [[1],[1,1]]
for i in range(2,numRows):
temp = [1]
for j in range(1,i):
temp.append(res[i-1][j-1] + res[i-1][j])
temp.append(1)
res.append(temp)
return res

参考

class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
triangle=[[1]*n for n in range(1,numRows+1)] for i in range(2,numRows): #第三行开始
for j in range(1,i): #第二列到倒数第二列
triangle[i][j]=triangle[i-1][j-1]+triangle[i-1][j]
return triangle

leetcode-easy-others-118 Pascal's Triangle的更多相关文章

  1. [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 ...

  2. 【leetcode❤python】118. Pascal's Triangle

    #-*- coding: UTF-8 -*-#杨辉三角class Solution(object):    def generate(self, numRows):        "&quo ...

  3. leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle

    118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...

  4. Leetcode#118. Pascal's Triangle(杨辉三角)

    题目描述 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2, ...

  5. LN : leetcode 118 Pascal's Triangle

    lc 118 Pascal's Triangle 118 Pascal's Triangle Given numRows, generate the first numRows of Pascal's ...

  6. 118. Pascal's Triangle

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...

  7. LeetCode(119) Pascal's Triangle II

    题目 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [ ...

  8. LeetCode Array Easy 118. Pascal's Triangle

    Description Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. I ...

  9. 【LeetCode】118. Pascal's Triangle 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  10. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

随机推荐

  1. Django框架——基础之路由系统(urls.py)

    1.URL路由系统前言 URL是Web服务的入口,用户通过浏览器发送过来的任何请求,都是发送到一个指定的URL地址,然后被响应. 在Django项目中编写路由,就是向外暴露我们接收哪些URL的请求,除 ...

  2. nodejs在Mac下的卸载

    卸载: 在 node 官网上下载的安装包,用安装包安装的node.应该可以用一下命令行卸载: 在终端输入以下命令: sudo rm -rf /usr/local/{bin/{node,npm},lib ...

  3. mysql数据库表名区分大小写

    使用mysql的时候,创建的表明都是大写的,但是查询语句中表明用消息就会报错,表不存在. 查询后发现mysql默认配置是表明区分大小写的,如果要修改成不区分大小写,需要修改一下配置. 1.修改MySq ...

  4. C# 类的继承和访问

    学习笔记------类的继承和访问: class MyBaseClass { public void PrintSun(){ Console.WriteLine("base111111111 ...

  5. 求二叉搜索树的第k小的节点

    题目描述: /** * 给定一棵二叉搜索树,请找出其中的第k小的结点. * 例如, (5,3,7,2,4,6,8)中, * 按结点数值大小顺序第三小结点的值为4. * 这是层序遍历: * 5 * 3 ...

  6. AntisymmetricRNN: A Dynamical System View on Recurrent Neural Networks(解析)

    原文链接:https://arxiv.org/abs/1902.09689 发表在:ICLR 2019 ------------------------------------------------ ...

  7. 数组转list

    例如String数组转成Integer泛型的List String [] pathArr = deptPath.split(","); Lit<Integer> dep ...

  8. 关于reverse()和sort()方法的返回值问题

    关于reverse()和sort()方法的返回值问题   先说结论:reverse()和sort()方法的返回值并不是当前步骤排序后的数组,而是数组的引用.   展示如下: var arr = [2, ...

  9. 【51nod 2026】Gcd and Lcm

    题目 已知 \(f(x)=\sum_{d|x}μ(d)∗d\) 现在请求出下面式子的值 \(\sum_{i=1}^{n}\sum_{j=1}^{n}f(gcd(i,j))∗f(lcm(i,j))\) ...

  10. django开发博客01-页面展示数据库中的数据

    1.首先在views.py中引入models.py的 Category这个类 然后在函数中(blog)写执行逻辑 categorys 返回的对象是是一个list"<QuerySet [ ...