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

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. 关于在Arduino中调用DS1302模块

    DS1302时钟模块中的电池是起掉电保存作用的,在实际运行中必须给他的GND和VCC供电,否则得到的是错误的时间. 也就是说,电池是保存日期的,而无法提供芯片正常运行所需的电力. 从芯片引脚上可以看出 ...

  2. data-ajax="false"

    转自:https://yq.aliyun.com/ziliao/265393 最近在做一个项目,由于涉及到跨平台性,所以采用了jquerymobile这个框架,在开发过程中,一开始为了图测试方便,采用 ...

  3. delphi 浮点 精度

    double 没有问题, Single有问题 '0.7' 0.69999999999999996 Single; // 4 byte real Double; // 8 byte real

  4. 【Consul】Consul实践指导-配置文件

    Agent有各种各样的配置选项,这些配置选项可以通过命令行参数的方式设定,也可用通过配置文件的方式设定--所有的配置选项都是可选的,当然也是有默认值的. 当加载配置选项时,consul是按照词典顺序从 ...

  5. nginx基本配置与参数说明-【转】

    #运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/error.log; ...

  6. No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer解决方法

    org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.poj ...

  7. 修改kvm虚拟机镜像大小

    修改虚拟机镜像大小(qcow2/raw resize) 创建一个镜像文件,大小1G taw muxueqz@muxueqz /tmp $ qemu-img create -f raw t.raw 1G ...

  8. 全部物料的交期都要加上两天 V_OUT_PR

    DUE_DATETIME加上两天就可以,如果只是部分物料的话,就要根据物料组或者别的一些条件去判断

  9. Mesos的资源分配

    Apache Mesos能够成为最优秀的数据中心资源管理器的一个重要功能是面对各种类型的应用,它具备像交警一样的疏导能力.本文将深入Mesos的资源分配内部, 探讨Mesos是如何根据客户应用需求,平 ...

  10. 导入txt文件到SQL SERVER 2008

    最近在学习数据库,想要试处理大量数据.大量的数据手动输入是不可能的了,所以需要导入.本人上网看了不少的教程,然后下载了txt格式的一万条彩票开奖记录数据.但是把这些数据导入到SQL Server 20 ...