题目:

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?

求杨辉三角(也叫帕斯卡三角)的第n行

杨辉三角百度百科链接

http://baike.baidu.com/link?url=7YQlDvHXtPgr6zVk-Vaw1YG8TncQHUuSNoOrx8f61sj2kG-XCFGPmqvttAn8nleqW46fKGGWTY9tYyB9F7YVTK

代码:

class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> A(rowIndex + , );
A[] = ;
for(int i = ; i < rowIndex + ; ++i)
for(int j = i; j >= ; --j)
{
A[j] = A[j] + A[j-];
}
return A;
}
};

[LeetCode119]Pascal's Triangle II的更多相关文章

  1. 每天一道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, ...

  2. LeetCode119. Pascal's Triangle II

    Description Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, ...

  3. 28. Triangle && Pascal's Triangle && Pascal's Triangle II

    Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...

  4. 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II

    118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  5. Pascal's Triangle,Pascal's Triangle II

    一.Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, giv ...

  6. 杨辉三角形II(Pascal's Triangle II)

    杨辉三角形II(Pascal's Triangle II) 问题 给出一个索引k,返回杨辉三角形的第k行. 例如,给出k = 3,返回[1, 3, 3, 1] 注意: 你可以优化你的算法使之只使用O( ...

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

  8. 118/119. Pascal's Triangle/II

    原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...

  9. LeetCode: Pascal's Triangle II 解题报告

    Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...

随机推荐

  1. 由“Jasperrpeorts 4.1.2升级到5.1.2对flex项目的解析”到AS3 带命名空间的XML的操作

    原文同步至:http://www.waylau.com/from-jasperrpeorts-4-1-2-upgraded-to-5-1-2-parsing-of-flex-projects-to-t ...

  2. 跨平台网络通信与server编程框架库(acl库)介绍

    一.描写叙述 acl project是一个跨平台(支持LINUX,WIN32,Solaris,MacOS,FreeBSD)的网络通信库及server编程框架,同一时候提供很多其它的有用功能库.通过该库 ...

  3. hdu4283(区间dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题意:有一个队列,每个人有一个愤怒值D,如果他是第K个上场,不开心指数就为(K-1)*D.但是边 ...

  4. 关于在ios7之后改变状态栏颜色

    看到网上都说 在ios7之后要这样设置 首先,须要在Info.plist配置文件里,添加键:UIViewControllerBasedStatusBarAppearance,并设置为YES: 然后,在 ...

  5. jenkins 集成 redmine 账户验证的方案

    jenkins 集成 redmine 账户验证的方案 赖勇浩(http://laiyonghao.com) 动机 Jenkins 是最著名的持续集成工具,又因为它开源免费.插件众多,成为了许多团队做持 ...

  6. 内存分析工具 MAT 的使用

    1 内存泄漏的排查方法 Dalvik Debug Monitor Server (DDMS) 是 ADT插件的一部分,当中有两项功能可用于内存检查 : ·    heap 查看堆的分配情况 ·     ...

  7. SWT中的GridLayout(转)例子不错

    GridLayout 是一个非常强大的布局管理器,它可以实现很多复杂的布局,名字中暗示它将所有控件放置在类似网格的布局中.^__^GridLayout 有两个构造函数. GridLayout的构造函数 ...

  8. SCSI miniport 驾驶一个简单的框架

    前段时间,只需用一台新电脑,由于资金有限没有匹配了心仪已久的SSD.我没感觉到飞翔的感觉,总不甘心,仔细想想.我死了相当大的存储,我们可以假设部分内存作为硬盘驱动器把它弄出来.不会比固态硬盘的速度快, ...

  9. JUnit4.8.2来源分析-6.1 排序和过滤

    Runner.sort.Request.sortWith和Sorter.apply yqj2065很快,他们搞死. Sorter.apply().Request.sortWith()和Sortable ...

  10. CentOS 6.4 文件夹打开方式

    CentOS 6.4 文件夹打开方式 在CentOS 6.4中,双击文件夹,默认会在新窗口中打开文件夹,没有路径.前进.后退这样的按钮,如果一个文件夹的路径很深,则需要打开n多的窗口才能找到最终想要的 ...