[leetcode] 2. 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,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?
就是输入k然后输出第k行帕斯卡三角【其实我一直把它叫杨辉三角】。
我这边思路是拿queue来不断弹出压入处理做那个二项式展开:
vector<int> getRow(int rowIndex)
{
int aspros, defteros;
aspros = defteros = ;
queue<int> tmp;
vector<int> Pascal; if (rowIndex == )
{
Pascal.push_back();
return Pascal;
} tmp.push();
tmp.push();
tmp.push(); for (int i = ; i < rowIndex; i++)
{
tmp.push();
do
{
aspros = tmp.front();
if (!tmp.empty())
tmp.pop();
defteros = tmp.front();
tmp.push(aspros + defteros);
} while (defteros != );
}
tmp.pop();
while (!tmp.empty())
{
Pascal.push_back(tmp.front());
tmp.pop();
} return Pascal;
}
queue和vector其实感觉还不熟,应该可以拿vector直接来做的【以后改】
[leetcode] 2. Pascal's Triangle II的更多相关文章
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- [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 (杨辉三角之二)
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 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 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, ...
- 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 ...
- C#解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 ...
- LeetCode(33)-Pascal's Triangle II
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...
随机推荐
- php Reflection
<?php function title($title, $name) { return sprintf("%s. %s\r\n", $title, $name); } $f ...
- Tkinter place() 方法
Python GUI - Tkinter place() 方法的使用例子: 这个的几何管理器组织放置在一个特定的位置,在他们的父widget部件. 语法: widget.place( place_ ...
- OpenLayers 3 之 切换图层控件
OpenLayers 3 之 切换图层控件 openlayers 3中并没有默认的图层切换控件,GitHub中有一个项目实现了我们需要的控件-------- ol3-layerswitcher . 可 ...
- 部署ASP.net MVC程序到IIS
转:http://www.cnblogs.com/piyeyong/archive/2012/08/15/2640004.html 在网上找到一个table,列举了不同的操作系统对应的IIS版本以及配 ...
- leetcode189
public class Solution { public void reverse(int[] nums, int start, int end) { while (start < end) ...
- GNU/Linux LVM 原理图释
逻辑卷管理器(英语:Logical Volume Manager,缩写为LVM),又译为逻辑卷宗管理器.逻辑扇区管理器.逻辑磁盘管理器,是Linux核心所提供的逻辑卷管理(Logical volume ...
- spring+mybatis之注解式事务管理初识(小实例)
1.上一章,我们谈到了spring+mybatis声明式事务管理,我们在文章末尾提到,在实际项目中,用得更多的是注解式事务管理,这一章将学习一下注解式事务管理的有关知识.注解式事务管理只需要在上一节的 ...
- 读书笔记 Week7 2018-4-19
<构建之法> 第十二章 用户体验 读书笔记 首先不得不说,现如今大部分的电脑使用者,都被微软的图形化界面把口味养刁了.当然,包括我自己.无论是在微机原理上级的时候使用那些带着浓郁的上世纪八 ...
- Python解释器种类以及特点 (经典概括, 便于理解和记忆)
CPython c语言开发的 使用最广的解释器 IPython 基于cpython之上的一个交互式计时器 交互方式增强 功能和cpython一样 PyPy 目标是执行效率 采用JIT技术 对pytho ...
- mongodb修改用户名密码
首先先将启动mongo的配置文件里面的 auth:用户认证,改为false. 正确做法,利用db.changeUserPassword db.changeUserPassword('tank2','t ...