LeetCode_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,3,1]. Note:
Could you optimize your algorithm to use only O(k) extra space?
class Solution {
public:
vector<int> getRow(int rowIndex) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> result(rowIndex+);
result[] = ;
int temp1 = , temp2 = ;
for(int i = ; i<= rowIndex ; i++)
for(int j = ; j< i+; j++){
temp2 = result[j];
if(j == || j == i)
result[j] = ;
else
result[j] += temp1 ;
temp1 = temp2;
}
return result;
}
};
LeetCode_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 ...
随机推荐
- QT中共享库的生成与使用
一. 静态库的生成1. 测试目录: lib2. 源码文件名: mywindow.h, mywindow.cpp, 类MyWindow继承于QPushButton, 并将文字设置为"I'm i ...
- 基于Redis的消息订阅/发布
在工业生产设计中,我们往往需要实现一个基于消息订阅的模式,用来对非定时的的消息进行监听订阅. 这种设计模式在 总线设计模式中得到体现.微软以前的WCF中实现了服务总线 ServiceBus的设计模式. ...
- 再论dynamic 关键字
有关动态数据类型 ,大家估计在实际中用的比较多了,不是很陌生.有关自己在项目中 的实际钉子总结: 1 匿名对象中的字段,是只读的,不能赋值 2 动态类型 指向强类型实例,注意观察内部的属性可访问性 ...
- 【转】关于Adapter的The content of the adapter has changed问题分析 关于Adapter的The content of the adapter has changed问题分析
原文网址:http://www.cnblogs.com/monodin/p/3874147.html 1.问题描述 1 07-28 17:22:02.162: E/AndroidRuntime(167 ...
- android ListView用法介绍
ListView在Android开发中是比较常用的组件,它是以列表的形式展示内容,并且还可以处理用户的选择与点击等操作: LIstView显示数据一般需要三方面: (1)ListView组件:用来展示 ...
- HDU5044---Tree 树链剖分
大致题意:add1 u v u到v路径上所有点的权值加上k,add2 u 到v路径上所有边的权值加上k 最后输出所有点的权值,边的权值..树链剖分预处理然后来个线性O(n)的操作.刚开始用线段树 ...
- 传阿里整合资源,进军O2O市场
阿里巴巴对于本地生活市场,以及O2O领域始终虎视眈眈.从最早的融合口碑网,到最近阶段推出淘宝点点.收购高德地图等一系列app产品,其整合线上线下消费市场的野心已十分明显. 今年年初,阿里巴巴集团重新进 ...
- python:学习defaultdict,namedtuple
# -*- coding: utf-8 -*-__author__ = 'Administrator'import bisect#排序说明:http://en.wikipedia.org/wiki/i ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...
- jQuery插件开发 格式与解析2
最近忙里偷闲玩一下js插件,经过自身的练习,感觉js插件还是挺好玩的.特此作如下笔记,给自己留个印象.例子形如: (1)类插件:classTool.js Code: (function($,expor ...