http://oj.leetcode.com/problems/pascals-triangle-ii/

杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algorithm to use only O(k) extra space?其实计算当前行,也只用到前一行了。再前面的没有用。

class Solution {
public:
vector<int> getRow(int rowIndex) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case. vector<int> onepiece;
if(rowIndex<)
return onepiece;
//
onepiece.push_back(); if(rowIndex == )
return onepiece;
//
onepiece.push_back();
if(rowIndex == )
return onepiece; //2...
vector<int> ans(onepiece);
for(int row = ;row<= rowIndex;row++)
{
onepiece = ans;
for(int index = ;index < row;index++)
{
ans[index] = onepiece[index - ]+onepiece[index];
}
ans.push_back();
}
return ans;
}
};

LeetCode OJ——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 a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...

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

  5. leetcode 【 Pascal's Triangle II 】python 实现

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

  6. 【leetcode】Pascal's Triangle II

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

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

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

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

随机推荐

  1. Vim编辑器基础

    Vim编辑器基础 vi:Visual Interface vim:VI iMproved Vim模式 1.编辑模式(命令模式) 只能下达命令,不能键入字符 2.输入模式 键入字符 3.末行模式 左下角 ...

  2. Python之简单Socket编程

    Socket编程这块儿还是比较重要的,记录一下:实现服务器端和客户端通信(客户端发送系统指令,如ipconfig等,服务器端执行该指令,然后将指令返回结果给客户端再传过去,设置一次最多直接收1024字 ...

  3. Virtual Friends HDU - 3172 (并查集+秩+map)

    These days, you can do all sorts of things online. For example, you can use various websites to make ...

  4. 使用jquery.layout.js构建页眉/页脚/左侧导航/中间展示内容的网页结构

    背景: 快速将一个页面分成几个部分,在导航和页眉的位置放置公用的元素. 准备: jquery.layout.js 首先,向页面中引入如下js文件和css文件,代码: <link href=&qu ...

  5. js中xml文件加载

  6. UVA10779Collectors Problem

    uva 10779 Collectors Problem Some candy manufacturers put stickers into candy bar packages. Bob and ...

  7. Windows清理打印池的方法

    另存为bat运行   @echo off title 快速清除打印队列 echo. echo 停止打印机服务 net stop spooler>nul echo. del /q /f %wind ...

  8. luogu2053 [SCOI2007]修车

    把m个师傅拆成n个阶段,考虑每个人选上第某个阶段的某师傅对答案做出的贡献. 参见这里与那里. #include <iostream> #include <cstring> #i ...

  9. ogre3D学习基础6---场景管理器的使用

    场景管理器的使用 最常使用的坐标系统空间(同时也是Ogre程序所能提供的)即是世界空间(World).父节点空间(Parent)以及本地空间(Local). 1.世界空间 就是物体所存在的地方,当我们 ...

  10. python - work5 - 类与对象 - 拓展题

    ''' 5:购物车类,包含的功能如下,请自行设计这个类以及类里面的方法:1)用户输入工资后,打印商品列表(商品列表自行设计展示模式)2)允许用户根据商品编号去选择商品3)用户选择商品后,检查余额是否足 ...