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 ...
随机推荐
- cell 重用
1. 当单元格因滚屏而脱落表格可见区时,表格可以将其缓存到重用队列中. 用法:我们可标记单元格以备重用,然后根据需要从该队列中提取. 在分配新单元格时,必须检查重用单元格是否可用.如果表格对deque ...
- synchronized一个(二)
今天遇到了一个关于synchronized的一个问题,关于其持有锁的问题.这个问题以前是有看过相关文章的,但是一直没有记录,今天大概记录一下当前的认知. 对于静态方法,synchronized的使用的 ...
- 一起来点React Native——你必须要会点FlexBox布局
一.FlexBox布局 1.1 FlexBox是什么意思呢? flexible(形容词):能够伸缩或者很容易变化,以适应外界条件的变化 box(名词):通用的矩形容器 1.2 什么是FlexBox布 ...
- Winform菜单之Menustrip
有窗体必定有菜单了,可以直接使用菜单组件,也可以使用按钮(按钮就没法显示级联菜单的形式了). 下面重点介绍一下各种菜单 1.Menustrip 最常用的莫过于此菜单了,从工具栏中拖入一个menustr ...
- Java并发编程之三:volatile关键字解析 转载
目录: <Java并发编程之三:volatile关键字解析 转载> <Synchronized之一:基本使用> volatile这个关键字可能很多朋友都听说过,或许也都用过 ...
- Linux系统下 MYSQL数据库中的数据库文件在本机内迁移 (需暂停服务的方式)
Linux系统下 MYSQL数据库中的数据库文件在本机内迁移 本机采用Ubuntu16.04系统,tar方式安装MySQL5.7.21 数据库安装文件夹为 /home/devil/mysql 现 ...
- python安装openSSL
首先确定您是否下载python (3).pip (3).python-wheel 官网下载源码包openSSL 参考:用pip安装python 模块OpenSSL
- Ubuntu下gcc的简单使用
一直不怎么用gcc,今天看了大神们的笔试题,不得不动手开始写程序了,差距那个大啊. gcc是ubuntu下的终端编译器,可以用来写C.C++的程序,简单用法如下: vim name1.c 先用vim打 ...
- Pandas dataframe 标记删除重复记录
Pandas提供了duplicated.Index.duplicated.drop_duplicates函数来标记及删除重复记录 duplicated函数用于标记Series中的值.DataFrame ...
- Mac OS Alfred 2 tips
From: http://www.uuair.cn/?p=64 写这个东西,我没敢叫指南之类,只能算是技巧,因为Alfred这个软件的强大,我还没研究明白,还有好多功能自己没搞懂,所以写一些我发现或者 ...