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 that the row index starts from 0.
Example:
Input: 3
Output: [1,3,3,1]
原题地址:Pascal's Triangle II
题意: 杨辉三角
代码:
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
res = [1]
for i in range(1, rowIndex+1):
for j in range(i-1, 0, -1):
res[j] = res[j]+res[j-1]
res.append(1)
return res
时间复杂度:O(n^2)
空间复杂度: O(n)
119. Pascal's Triangle II@python的更多相关文章
- 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, ...
- 118/119. Pascal's Triangle/II
原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...
- 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 Pascal's Triangle && Pascal's Triangle II Python
Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...
- [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 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- leetcode 119 Pascal's Triangle II ----- java
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
随机推荐
- 如何使用Xshell连接VMware上的Linux虚拟机
前序:最近开始研究Hadoop平台的搭建,故在本机上安装了VMware workstation pro,并创建了Linux虚拟机(centos系统),为了方便本机和虚拟机间的切换,准备使用Xshell ...
- Linux 中 ip netns 命令
通过 ip netns help 可以查看所有关于ip netns的命令: network namespace 在逻辑上是网络堆栈的一个副本,它有自己的路由.防火墙规则和网络设备. ip netns ...
- thinkphp5使用前置后置操作
下面举个例子,前置删除的例子 模型事件只可以在调用模型的方法才能生效,使用查询构造器通过Db类操作是无效的 控制器中实例化类 $cate=model('cate'); $cate-> ...
- Domination
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ , f ...
- PAT甲级——1114 Family Property (并查集)
此文章同步发布在我的CSDN上https://blog.csdn.net/weixin_44385565/article/details/89930332 1114 Family Property ( ...
- 题解 BZOJ 1037 & Luogu P2592 [ZJOI2008]生日聚会
BZOJ & Luogu 老师说是背包?并没看出来QAQ 设f[i][j][o][p]表示已经选了i个人,j个男生,男生比女生最多多o个,女生比男生最多多p个时的方案数 两种转移: <= ...
- java课后思考问题(七)
1.继承条件下的构造方法调用 package parent;class Grandparent { public Grandparent() { System.out.println("Gr ...
- nginx一个简单的反向代理设置
location /aaaaa/ { proxy_pass http://localhost:8080/aaaaa/; } 经过配置,现在访问 http://localhost/aaaaa/ 就会 ...
- 【干货分享】大话团队的GIT分支策略进化史
封面 作为一名85后的技术男,一转眼10年过去了(一不小心暴露了年龄,虽然我叫18岁fantasy),亲手写代码已经是5年前了,目前主要负责公司的软件产品的规划和设计(所以最近写的东西也主要与设计和产 ...
- vuex填坑记录
vuex是需要等待页面加载完成后才会更新的,如果页面点击刷新有用到vuex的地方,那么vuex会保持旧的数据,等刷新完成后vuex的数据才会重置,所以要在页面加载后再调用vuex的数据才是正确的,如果 ...