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

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. Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process

    (THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920. ...

  2. [转] C#实现在Sql Server中存储和读取Word文件 (Not Correct Modified)

    出处 C#实现在Sql Server中存储和读取Word文件 要实现在Sql Server中实现将文件读写Word文件,需要在要存取的表中添加Image类型的列,示例表结构为: CREATE TABL ...

  3. myBaits缓存

    转自:https://blog.csdn.net/zhongzh86/article/details/50019511 9. Mybatis 缓存 正如大多数持久层框架一样,MyBatis 同样提供了 ...

  4. 关于java中的OutOfMemory种类和解决方法

    1.OutOfMemory的三种情况 1) 永久区溢出 Exception in thread "main" java.lang.OutOfMemoryError: PermGen ...

  5. VS2017更新后 在WIN7上找不到 stdio.h等的问题

    项目->属性->配置属性->常规->windows SDK版本.将其换成你现在的版本即可解决问题,如果不行就重新下个最新版SDK,如WIN10的.

  6. MongoDB动态条件之分页查询

    一.使用QueryByExampleExecutor 1. 继承MongoRepository public interface StudentRepository extends MongoRepo ...

  7. HttpServletResponse返回页面弹窗

    下载方法: @RequestMapping(value = "/download.htm") public void downLoadFile(String id,HttpServ ...

  8. What is _MainTex_ST ?

    [What is _MainTex_ST ?] 在Unity自带的Unlit/Texture中,有引用到float4 _MainTex_ST,如下: // Unlit shader. Simplest ...

  9. FP寻源报错

    ERROR [HY000] [Oracle][ODBC][Ora]ORA-01114: IO error writing block to file  (block # )  ORA-01114: I ...

  10. css3中的transform、transition、translate、animation(@keyframes)的区别

    一.前言 在CSS中,我们经常会使用到transform.transition.translate.animation(@keyframes)这些长得相似,又不好区分的属性(值).每当需要使用它们,都 ...