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, ...
随机推荐
- Node.js 内置模块crypto加密模块(2) AES
AES:高级加密标准 ( Advanced Encryption Standard ) AES是一种对称加密算法:加密需要密钥,且加密密钥和解密密钥相同 下面是AES加密的Node实现: " ...
- HTTPRunner实践二——参数化之生成UUID
接口测试中,需要使用到UUID,用来生成唯一ID. 1.什么是UUID UUID是128位的全局唯一标识符,通常由32字节的字符串表示.它可以保证时间和空间的唯一性,也称为GUID,全称为:UUID ...
- Maven项目已启动但是报异常访问webapp下所有资源都404
- vuex初使用(写的当然是最简单的应用啦)
关于vuex的简图 vuex文档:https://vuex.vuejs.org/zh-cn/installation.html 一:npm安装 npm install vuex --save 在mai ...
- Django-Rest-Framework的序列化之serializers 序列化组件
Django-Rest-Framework的序列化之serializers 序列化组件 restful framework 正常的序列化 from django.http import HttpRes ...
- 牛客假日团队赛2 F.跳跃
链接: https://ac.nowcoder.com/acm/contest/924/F 题意: Farmer John为了满足奶牛对美的享受而安装了人工湖.矩形的人工湖分成M行N列(1 <= ...
- 长春理工大学第十四届程序设计竞赛(重现赛)L.Homework Stream
链接:https://ac.nowcoder.com/acm/contest/912/L 题意: 作为大珩班尖子生,小r每天有很多作业要完成,例如工图.工图和工图. 很显然,做作业是要有顺序的.作业之 ...
- Even-odd Boxes hackerrank 分类讨论
https://www.hackerrank.com/contests/101hack50/challenges/even-and-odd-boxes/editorial 昨晚做的时候卡了挺久的. 首 ...
- scau 18087 开始我是拒接的 mobius
其实有一个很有用的技巧就是,把gcd = 4的贡献,压去gcd = 2时的贡献,就不需要考虑这么多的了. 为什么可以把gcd = 4的,压去gcd = 2的呢,gcd = 12的,压去gcd = 6的 ...
- 将JWT与Spring Security OAuth结合使用
1.概述 在本教程中,我们将讨论如何使用Spring Security OAuth2实现来使用JSON Web令牌. 我们还将继续构建此OAuth系列的上一篇文章. 2. Maven配置 首先,我们需 ...