我是按难度往下刷的,第二道是帕斯卡三角形二。简单易懂,题目如下:

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的更多相关文章

  1. 【LeetCode】Pascal's Triangle II 解题报告

    [LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...

  2. [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, ...

  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, ...

  4. [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 ...

  5. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  6. 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 ...

  7. 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, ...

  8. 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 ...

  9. 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  ...

  10. 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 ...

随机推荐

  1. Windbg在.net性能问题排查hang情况的应用思路

    1.使用~*kb 2000 查看本地锁的callstack情况,有sleep的线程关注是否占用锁,有wait等待的线程可能是正在等待锁资源. 2.使用~*e!clrstack 查看.net的calls ...

  2. fatal error C1010: 在查找预编译头时遇到意外的文件结尾 (转)

    错误描述:fatal error C1010: 在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "stdafx.h"”? 错误分析:     此错误发生 ...

  3. Spring Boot tomcat参数

    主题 初学SpringBoot,想要配置一下tomcat的端口,以前tomcat直接在它的XML里配置就好了.现在SpringBoot直接继承了,不知道哪里配置.后来找到解决方法,记录一下. 具体方法 ...

  4. KVM镜像image 转换 调整

    qemu-img create -f raw test.raw 8G 创建一个raw格式,大小为8G的镜像. qemu-img info disk1.qcow2     #查看镜像大小及实际占用多少空 ...

  5. objective-C中的"非正式协议"和“正式协议”

    objective-C中的接口与泛型 先承认我是标题党,因为在obj-c的世界中,官方根本没有"接口"与"泛型"这样的说法. 不过在obj-c中有二个与之接近的 ...

  6. Java Socket编程之UDP

    UDP编程: 将要传输的数据定义成数据包(Datagram),在数据报中指明所要到达的Socket(主机地址和端口号),然后再将数据报发送出去. 相关操作类:     DatagramPacket   ...

  7. Java如何快速修改Jar包里的文件内容

    需求背景:写了一个实时读取日志文件以及监控的小程序,打包成了Jar包可执行文件,通过我们的web主系统上传到各个服务器,然后调用ssh命令执行.每次上传前都要通过解压缩软件修改或者替换里面的配置文件, ...

  8. 接口自动化 Windows + HttpRunner 初探(一)

    运行环境 HttpRunner 是一个基于 Python 开发的测试框架,可以运行在 macOS.Linux.Windows 系统平台上. HttpRunner 的开发环境为 macOS + Pyth ...

  9. iOS调试程序的方法

    IOS各种调试技巧豪华套餐 普通操作 如图3 基本的断点操作如下 图4 点击那个黑列列就创建了一个断点,再次点击就临时取消这个断点(但是不删除),长按那个断点拖出去就删除了(mac os的系统工程师就 ...

  10. springboot用于web开发

    1.使用SpringBoot:1)创建SpringBoot应用,选中我们需要的模块:2)SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来3)自己编写业务代码 ...