Pascal's Triangle II
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> v;
if( rowIndex < ) return v; v.push_back();
if(rowIndex == ) return v; v.push_back();
if(rowIndex == ) return v; vector<int> v1; for(int row=;row<=rowIndex;row++){ v1.push_back();
int pre_len = v.size();
for(int i=;i<pre_len-;i++){
v1.push_back(v[i]+v[i+]);
}
v1.push_back();
v=v1; //vector 拷贝好方便啊
v1.clear();
}
return v;
}
};
Pascal's Triangle II的更多相关文章
- 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 ...
- 【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, ...
- Pascal's Triangle,Pascal's Triangle II
一.Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, giv ...
- 杨辉三角形II(Pascal's Triangle II)
杨辉三角形II(Pascal's Triangle II) 问题 给出一个索引k,返回杨辉三角形的第k行. 例如,给出k = 3,返回[1, 3, 3, 1] 注意: 你可以优化你的算法使之只使用O( ...
- 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, ...
- 118/119. Pascal's Triangle/II
原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...
- LeetCode: Pascal's Triangle II 解题报告
Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...
- 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4
当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...
- LeetCode Pascal's Triangle && Pascal's Triangle II Python
Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...
- 119. Pascal's Triangle II@python
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
随机推荐
- php 扩展dll
一.准备工作: 注:php5.2没有vc9,php5.3.php5.4没有vc6.呵呵.PHP5.5开始,不支持xp和win2003了,更是vc11了.--------------->所以,扩展 ...
- ie无法下载 无法打开该internet站点.请求的站点不可用或无法找到.请稍后重试
PK找的: http://support.microsoft.com/kb/316431/ 症状 ... 如果服务器使用着安全套接字层 (SSL) 并且已将下面的两个 HTTP 标头或其中的一个添加到 ...
- 中国电信某站点JBOSS任意文件上传漏洞
1.目标站点 http://125.69.112.239/login.jsp 2.简单测试 发现是jboss,HEAD请求头绕过失败,猜测弱口令失败,发现没有删除 http://125.69.112. ...
- [BS-06] 设置release发布时NSLog不打印设置
设置release发布时NSLog不打印设置 前提:在XCode做开发调试时往往需要打印一些调试信息做debug用,大家知道当打印信息的地方多了之后在模拟器上跑可能不会有什么问题,因为模拟器用的是电脑 ...
- Thread 线程
线程 Join 一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行 using System.Linq; using System.Text; using System.T ...
- 随机数产生random
随机数产生推荐用random(),在产生随机数前要添加种子srandom((unsigned int)time(NULL)). SYNOPSIS #include <stdlib.h> l ...
- django上传下载大文件
上传 def upFile(file): upload_dir = '/tmp/upload/%s' % username if request.method == 'POST': upload_fi ...
- 数据库调优过程(一):SqlServer批量复制(bcp)[C#SqlBulkCopy]性能极低问题
背景 最近一段给xx做项目,这边最头疼的事情就是数据库入库瓶颈问题. 环境 服务器环境:虚拟机,分配32CPU,磁盘1.4T,4T,5T,6T几台服务器不等同(转速都是7200r),内存64G. 排查 ...
- node.js npm权限问题try running this command again as root/Administrator.
npm install报错; try running this command again as root/Administrator. 以管理员身份打开cmd 开始菜单->所有程序->附 ...
- Lintcode: Segment Tree Build
The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...