Description

Given an index k, return the kth row of the Pascal’s triangle.

For example, given k = 3,

Return [1,3,3,1].

my program

class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res = {1};
for(int i = 1; i<=rowIndex; i++)
{
res.push_back(0);
for(int j = res.size(); j>0; j--)
{
res[j] += res[j-1];
}
}
return res;
}
};

34 / 34 test cases passed.

Status: Accepted

Runtime: 0 ms

other methods

vector<int> getRow(int rowIndex) {
vector<int> ans(rowIndex+1,1);
int small = rowIndex/2;
long comb = 1;
int j = 1;
for (int i=rowIndex; i>=small; i--){
comb *= i;
comb /= j;
j ++;
ans[i-1] = (int)comb;
ans[j-1] = (int)comb;
}
return ans;
}

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

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

  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. 记录一次Elasticsearch线上部署后出现:org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []的问题解决

    说明:ES部署了3个节点,而一般情况只要这三个节点的IP其中一个都可以连接,Web端口使用的是9500,Client连接使用的是9600,调用程序使用了ES原生Client进行连接. 解决方法: 1. ...

  2. android连接Mysql数据库之JDBC方式

    一.创建一个数据库和若干表,并导入相关信息.这里以我之前使用的一个图书系统的数据库为例子. 首先假设已经安装并配置好Mysql.(建议大家安装WAMP,也就是安装完这个,就相当于安装了Mysql,PH ...

  3. Centos7.3 bbc tools安装

    http://blog.csdn.net/orangleliu/article/details/54099528 更新到最新 CentOS 7.3 1611 yum update -y cat /et ...

  4. Nagle算法&&延时确认

    数据流分类 成块数据 交互数据   Rlogin需要远程系统(服务器)回显我们(客户)键入的字符 数据字节和数据字节的回显都需要对方确认 rlogin 每次只发送一个字节到服务器,而Telnet 可以 ...

  5. Merge的山寨版“联机帮助”

    IF NOT OBJECT_ID('Demo_AllProducts') IS NULL DROP TABLE Demo_AllProducts GO CREATE TABLE Demo_AllPro ...

  6. python 字典dict和列表list的读取速度问题, range合并

    python 字典和列表的读取速度问题 最近在进行基因组数据处理的时候,需要读取较大数据(2.7G)存入字典中,然后对被处理数据进行字典key值的匹配,在被处理文件中每次读取一行进行处理后查找是否在字 ...

  7. SQLSERVER调用DLL程序

    在SQL Server中调用dll分为两个步骤 1.创建一个dll文件(dll文件分成3种类型,讲其中一种) 2.把dll文件放进SQL Server的程序集中.然后定义一个Function,就可以通 ...

  8. Java开发中的23种设计模式详解 【转】

    创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 行为型模式,共十一种:策略模式.模板方法模式.观察者模式.迭代子模式.责任链模式.命令模式.备忘录模式.状态模式.访问 ...

  9. http://blog.csdn.net/hahalzb/article/details/5889545

    http://blog.csdn.net/hahalzb/article/details/5889545

  10. new Thread(new ThreadStart(this.StartServer))

    Thread .new thUdpServer thUdpServer = new Thread(new ThreadStart(this.StartServer))