LeetCode题解之Pascal's Triangle II
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的更多相关文章
- 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, ...
- 【一天一道LeetCode】#119. Pascal's Triangle II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【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 [ ...
- 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 ...
- 【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 ...
- LeetCode算法题-Pascal's Triangle II(Java实现)
这是悦乐书的第171次更新,第173篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第30题(顺位题号是119).给定非负索引k,其中k≤33,返回Pascal三角形的第k ...
- 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4
当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...
- 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- ...
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
随机推荐
- This Gradle plugin requires Studio 3.0 minimum
从github上下载的项目遇到一个问题:Error:This Gradle plugin requires Studio 3.0 minimum 意思就是说studio版本不高,导入的项目的版本是3. ...
- wordpress获取文章所属分类
1.获取全部分类 <?php foreach((get_the_category()) as $category){ echo $category->cat_name; } ?> 2 ...
- 安装flutter和dart总结
1 manjaro从软件仓库安装就行,但是也可以下载安装包.然后添加到Path目录 我是安装dart从软件仓库, flutter下载压缩包添加到path 1.1 需要将android sdk , ex ...
- redis学习(一) redis的介绍与安装
redis简单介绍 redis全称remote-dictionary-server 直译为远程字典服务器, 是一个高性能的key-value存储系统,也被称为数据结构服务器,因为其所存储的数据值(va ...
- 复刻smartbits的国产网络测试工具minismb-如何添加数据流
复刻smartbits的国产网络性能测试工具minismb,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此工具测试任何ip网络设备的端口吞吐率,带宽,并发连接数 ...
- 我眼中的优秀技术leader
在这家公司工作的四年时间里,我一共接触过两个在技术团队里有很大影响力的leader.本文将基于我在工作中对他们的观察,总结一下他们身上所具有的特质,以作为自己学习的榜样.标题中的“我眼中的”,不仅表示 ...
- linux----之tcpdump小用
1.通过抓包大致确定访问量 #time tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn' -c 10000 >/dev/null 根据real时间判断访 ...
- GoogLeNetv3 论文研读笔记
Rethinking the Inception Architecture for Computer Vision 原文链接 摘要 卷积网络是目前最新的计算机视觉解决方案的核心,对于大多数任务而言,虽 ...
- multiset多重集合容器(常用的使用方法总结)
关于C++STL中multiset集合容器的学习,看别人的代码一百遍,不如自己动手写一遍. multiset多重集合容器和set集合容器的使用方法大多相同,不同的是multiset多重集合容器允许重复 ...
- 我的Visual Studio必用工具
自己备用 代码生成工具:Resharper 代码颜色:supercharger 高亮单词 Word highlight with margin Productivity Power Tools 详细介 ...