119. Pascal's Triangle II (Graph; WFS)
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> a(rowIndex + );
a[] = ;
for(int i = ; i <= rowIndex; i++) //遍历行
for(int j = i; j >= ; j--) //遍历行中的元素,第k行有k个元素。注意行中元素需要从右往左遍历,否则下一行填写的结果会覆盖上一行还未使用的元素
if (j == i)
a[j] = a[j-];
else if (j == )
a[j] = a[j];
else
a[j] = a[j-] + a[j];
return a;
}
};
119. Pascal's Triangle II (Graph; WFS)的更多相关文章
- 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- ...
- 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] 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
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- [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 ----- java
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Java [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 ...
随机推荐
- Nginx(Windows)
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器. 反向代理方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将 ...
- 博客(第0次作业)—— New Starting Point
一.最理想的师生关系是健身教练和学员的关系,在这种关系中你期望获得来自老师的那些帮助? 正如文章中所说,这些学员的想法得足够强烈, 他/她才会花钱去参加这样的健身活动,每一个来学习的学生, 都是想学 ...
- 移动端H5调用摄像头(选择上传图片)
<label>照相机</label> <input type="file" id='image' accept="image/*" ...
- rabbitmq学习(一):AMQP协议,AMQP与rabbitmq的关系
前言 当学习完AMQP的基本概念后,可以到http://tryrabbitmq.com/中利用rabbitmq模拟器进行消息的模拟发送和接收 一.什么是AMQP,AMQP与rabbitmq的关系 AM ...
- cocos2dx 3.0 +VS2013 环境搭建
1.需要javasdk,android sdk,ndk,python 2.各种环境变量配置如下: JAVA_HOME:C:\Program Files\Java\jdk1.7.0_67 Path:%J ...
- bootstrap class sr-only 什么意思?
bootstrap class sr-only 什么意思? 在看 bootstrap 内联表单时,label 有一个 class 是 sr-only. sr-only 是给屏幕阅读器用的,是给视力不方 ...
- 什么是Spark(四)运算过程中的黑科技
Spark在运算过程中提供了一套完整的机制用来提高效率. 1. 用于收集信息的Accumulator,自带增量,用于spark全局收集数据:共享数据: 2. 用于提高传输速率的broadcast机制: ...
- CF 914G Sum the Fibonacci——子集卷积
题目:http://codeforces.com/contest/914/problem/G 第一个括号可以子集卷积:第三个括号可以用 FWT 异或卷积:这样算出选两个数组成 x 的方案数:三个部分的 ...
- 对类 sizeof
sizeof一个类的时候,都什么会被计算?静态成员会被计算进来么?如果这是一个子类,它的父类成员会被计算么? #include <iostream> using namespace std ...
- LCD的接口类型详解
LCD的接口有多种,分类很细.主要看LCD的驱动方式和控制方式,目前手机上的彩色LCD的连接方式一般有这么几种:MCU模式,RGB模式,SPI模式,VSYNC模式,MDDI模式,DSI模式.MCU模式 ...