leetcode python3 简单题119. Pascal's Triangle II
1.编辑器
我使用的是win10+vscode+leetcode+python3
环境配置参见我的博客:
链接
2.第一百一十九题
(1)题目
英文:
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal’s triangle.
Note that the row index starts from 0.
中文:
给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/pascals-triangle-ii
(2)解法
动态规划
(耗时:40ms,内存:13.7M)
class Solution:def getRow(self, rowIndex: int) -> List[int]:if(rowIndex==0):return [1]dp=[1,1]for i in range(3,rowIndex+2):cur=[0]*(i)cur[0]=cur[-1]=1for j in range(1,i-1):cur[j]=dp[j-1]+dp[j]dp=curreturn dp
注意:
1.dp=[1,1]
是rowIndex=1的情况。
2.cur=[0]*(i)
与cur=[0]*i
是一样的。
3.cur[0]=cur[-1]=1
最左最右都为1。
leetcode python3 简单题119. Pascal's Triangle II相关推荐
- leetcode python3 简单题118. Pascal's Triangle
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十八题 (1)题目 英文: Given a non-negative int ...
- [LeetCode]119.Pascal's Triangle II
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/SunnyYoona/article/details/43562603 题目 Given an ind ...
- LeetCode 119. Pascal’s Triangle II
119. Pascal's Triangle II My Submissions QuestionEditorial Solution Total Accepted: 72147 Total Subm ...
- leetcode python3 简单题225. Implement Stack using Queues
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十五题 (1)题目 英文: Implement the following ...
- leetcode python3 简单题70. Climbing Stairs
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...
- leetcode python3 简单题69. Sqrt(x)
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十九题 (1)题目 英文: Implement int sqrt(int x). ...
- leetcode python3 简单题53. Maximum Subarray
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十三题 (1)题目 英文: Given an integer array num ...
- leetcode python3 简单题58. Length of Last Word
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...
- leetcode python3 简单题14. Longest Common Prefix
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第十四题 (1)题目 英文: Write a function to find th ...
最新文章
- ThreadLocalMap的enrty的key为什么要设置成弱引用
- (POJ-3279)Fliptile (dfs经典---也可以枚举)
- java 画布实验报告_编辑画布图像
- 《IBM-PC汇编语言程序设计》(第2版)【沈美明 温冬婵】——第十一章——自编解析与答案
- 【机器学习笔记四】分类算法 - 逻辑回归
- linux系统上传下载命令rz和sz
- MySql字符串与时间日期之间的的转换
- solr 使用记录 - solr dataimporter 定时任务
- java同一程序只运行一次_如何使自己的程序只运行一次
- 细等线体cass_CAD中,刚打开一个文件,细等线体显示不出来,然后换个字体后在换回细等线体才正常显示,怎么回事?...
- ps景观平面图转鸟瞰图_小清新ps做景观鸟瞰图
- 如何申请免费SSL证书?宝塔面板SSL证书安装部署完整教程
- python extension package_Python Extension Packages for Windows所有包下载
- 苹果手机用计算机打不开,苹果手机更新ios11后,照片在电脑上打不开怎么办?...
- java short 写法_Java数据类型short的使用方法
- 美国电子烟走向规范化,“下一站”是中国?
- 微信用户与第三方网站用户的绑定策略(实现用户第一次登陆后永久免登陆)
- centos7安装ifconfig命令
- PostgreSQL之如何敲开PG的大门?
- deepfakes怎么用_手把手教你使用 Deepfakes 换脸