leetcode-easy-others-118 Pascal's Triangle
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的更多相关文章
- [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 ...
- 【leetcode❤python】118. Pascal's Triangle
#-*- coding: UTF-8 -*-#杨辉三角class Solution(object): def generate(self, numRows): "&quo ...
- 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- ...
- Leetcode#118. Pascal's Triangle(杨辉三角)
题目描述 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2, ...
- LN : leetcode 118 Pascal's Triangle
lc 118 Pascal's Triangle 118 Pascal's Triangle Given numRows, generate the first numRows of Pascal's ...
- 118. Pascal's Triangle
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- 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 [ ...
- LeetCode Array Easy 118. Pascal's Triangle
Description Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. I ...
- 【LeetCode】118. Pascal's Triangle 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- Wayos网吧路由英雄联盟频繁掉线解决办法
英雄联盟某些机器瞬间ping值飙升,然后一直掉线重连!研究好久,解决了,经验与大家分享 第一步,在路由器地址后加qos_ext.htm进入qos参数设置页面(如果出现不了设置界面请更新固件).比如:h ...
- centos 7 搭建 LNMP ( Linux+Nginx+MySQL+PHP )
操作系统 | CentOS Linux release 7.6.1810 (Core) [root@localhost ~# cat /etc/redhat-release CentOS Linux ...
- Linux中FTP服务器配置
1.FTP服务器的一些基本概念 (1)FTP连接方式 控制连接:标准端口为21,用于发送FTP命令信息. 数据连接:标准端口为20,用于上传.下载数据. ...
- Jdk1.8的安装(Linux和windows)
1.1 JDK1.8下载地址 JDK下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. ...
- Itextpdf + Adobe Acrobat DC填充模板生成pdf快速入门
Itextpdf + Adobe Acrobat DC填充模板生成pdf快速入门 生成pdf有很多种方法,如通过freemarker,或 使用itextpdf.本文将使用itextpdf生成pdf 1 ...
- xss技巧记录
1.iframe的srcdoc属性 先演示一下 <iframe srcdoc="<script>alert(1)</script>"> 浏览器渲 ...
- vs code 保存显示无法写入文件的解决方法
右键文件夹点击属性 选择安全 把当前用户权限都勾选上就可以了
- noi.ac NA529 【神树的矩阵】
表示今天一发A了这题拿了rk3...是个sb构造... 考虑除了\(n=1/m=1\)的情况,最小次数\(ans\)不会\(>3\). 对于\(n=1/m=1\),暴力即可. 然后考虑\(ans ...
- STM32CUBE+KEIL+Compiler V6使用方法
可以参考:https://blog.csdn.net/PeterSun01/article/details/90445439https://www.jianshu.com/p/18a58fee94ce ...
- 【leetcode】1250. Check If It Is a Good Array
题目如下: Given an array nums of positive integers. Your task is to select some subset of nums, multiply ...