118/119. Pascal's Triangle/II
原文题目:
读题:
杨辉三角问题
'''118'''
class Solution(object):
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if not numRows:
return []
result = []
for i in range(numRows):
result.append([1])
for j in range(1, i+1):
if j == i:
result[i].append(1)
else:
result[i].append(result[i-1][j] + result[i-1][j-1])
return result
'''119'''
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
result = [1]
if not rowIndex:
return result
for i in range(1,rowIndex+1):
temp = result
result = []
result.append(1)
for j in range(len(temp)-1):
result.append(temp[j] + temp[j+1])
result.append(1)
return result
118/119. Pascal's Triangle/II的更多相关文章
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- 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 OJ 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- leetcode 生成杨辉三角形, 118 119 Pascal's Triangle 1,2
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- 119. Pascal's Triangle II@python
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- leetcode 生成杨辉三角形, 118 119 Pascal's Triangle 1,2
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- 118. 119. Pascal's Triangle -- 杨辉三角形
118. Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- [LeetCode]题解(python):119 Pascal's Triangle II
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...
- 【一天一道LeetCode】#119. Pascal's Triangle II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
随机推荐
- RHEL7安装图像化桌面
RHEL7安装图像化桌面 作者:Eric 微信:loveoracle11g 在安装系统的时候选择的是默认的Minimal Install RHEL7系统安装完成开机启动后发现没有图形化 Linux系统 ...
- 在线学习和在线凸优化(online learning and online convex optimization)—FTL算法5
最自然的学习规则是使用任何在过去回合中损失最小的向量. 这与Consistent算法的精神相同,它在在线凸优化中通常被称为Follow-The-Leader,最小化累积损失. 对于任何t: 我们谈到了 ...
- css3凹角效果
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...
- 第31课 老生常谈的两个宏(linux)
1. Linux内核中常用的两个宏定义 (1)offsetof宏:用于计算TYPE结构体中MEMBER成员的偏移位置 #ifndef offsetof #define offsetof(TYPE, M ...
- 利用NPOI导出数据到Execl
相信很多童鞋都开发过Execl的导入导出功能,最近产品中无论是后台数据分析的需要,还是前端满足用户管理的方便,都有Execl导入导出的维护需求产生. 以前做这个功能,如果是web,利用HttpCont ...
- 大数据Web可视化分析系统开发
下载地址 https://tomcat.apache.org/download-70.cgi 打开我们的idea 这些的话都可以按照自己的需求来修改 在这里新建包 新建一个java类 package ...
- Ramdisk虚拟内存盘,Swap分区
虚拟内存盘是通过软件将一部分内存(RAM)模拟为硬盘来使用的一种技术.相对于直接的硬盘文件访问来说,这种技术可以极大的提高在其上进行的文件访问的速度.但是RAM的易失性也意味着当关闭电源后这部分数据将 ...
- C# ORM修改实体层
实体层:[数据库中是么以偶Contents2这个字段的],之所以在实体层添加一个Contents2,是因为: 所以在添加之后: 返回json形式,就用Contents,后台添加就用Contents2. ...
- 05python上
location 位置 untitled 未命名的 fullstack 全栈 interpreter 解释器 字符格式化输出 占位符 %s s = string %d d = digit 整数 %f ...
- ASPxCallbackPanel(珍藏版)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AspxCallbackPane ...