1、题目描述

2、题目分析

题目要求返回杨辉三角的某一行,需要将杨辉三角的某行的全部计算出来。

3、代码实现

  vector<int> getRow(int rowIndex) {

         if( rowIndex ==  )
return vector<int>(,); vector<int>b{,};
int n = ;
while(n <= rowIndex){
vector<int> r = calNextline(b);
b.resize( r.size() );
for(int i = ; i < r.size(); i++){
b[i] = r[i];
}
n++;
} return b;
} vector<int> calNextline( vector<int> v){
if( v.size() < ){
return v;
} vector<int> rv(v.size() + , ); for(int i = ; i < v.size()-; i++){
rv[i+] = v[i] + v[i+];
}
return rv;
}

LeetCode题解之Pascal's Triangle II的更多相关文章

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

  2. 【一天一道LeetCode】#119. Pascal's Triangle II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

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

  4. Leetcode No.119 Pascal's Triangle II(c++实现)

    1. 题目 1.1 英文题目 Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's tria ...

  5. 【LeetCode OJ】Pascal's Triangle II

    Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...

  6. LeetCode算法题-Pascal's Triangle II(Java实现)

    这是悦乐书的第171次更新,第173篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第30题(顺位题号是119).给定非负索引k,其中k≤33,返回Pascal三角形的第k ...

  7. 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4

    当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...

  8. leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle

    118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...

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

    [LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...

随机推荐

  1. 推荐一个 MYSQL 的命令行的客户端 MYCLI

    MYCLI 是一个 MySQL 命令行客户端工具 , 可以实现自动补全(auto-completion)和语法高亮,平时测试环境维护一些数据还是蛮方便的. https://github.com/dbc ...

  2. Android中Serializable和Parcelable序列化对象详解

    学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Parcelable进行序列化操作 5.P ...

  3. JavaScript -- Math

    ----- 016-Math.html ----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  4. Jmeter报错之jmeter.gui.action.ActionRouter: Error processing gui.action.Start@1b7c473a java.lang.ArrayIndexOutOfBoundsException

    一个使用了很久的Jmeter脚本,运行时Jmeter的UI界面上点击绿色按钮后,完全无反应,只有log报错,如下: 2017/06/28 14:29:23 ERROR - jmeter.gui.act ...

  5. docker-dockerfile使用

    使用 centos基础镜像, 构建dockerfile-ngix 简单说, 就是把需要做的东西写下来, 然后build的时候, 自动运行 一般包含:  基础镜像信息 维护者信息 镜像操作指令 容器启动 ...

  6. C语言版 Hello World

    C语言的Hello World 程序, 需要引入 <stdio.h> 头文件,输出使用 printf()方法: #include <stdio.h> int main() { ...

  7. 【IT笔试面试题整理】位操作

    如何准备: Bit manipulation can be a scary thing to many candidates, but it doesn't need to be! If you're ...

  8. 第一次项目上Linux服务器(五:CentOS7下Mysql数据库的安装与配置(转))

    好像在CentOS 7系统中,默认安装的mysql是它的分支mariadb.所以不能像CentOS-6.3那样安装,如下: [root@izwz ~]# yum -y install mysql my ...

  9. elasticSearch6源码分析(12)DiscoveryModule

    1.DiscoveryModule概述 /** * A module for loading classes for node discovery. */ 2.discovery The discov ...

  10. spring cloud zuul在使用中遇到的坑 : 转发时自动去掉prefix

    在使用zuul的时候遇到的坑总结一下: 逐渐增加更新以后遇到的 1.在路由的时候莫名其妙的把serviceId给去掉,导致404.比如请求:/serviceId/search/book,zuul会把s ...