119. Pascal's Triangle II
2016-02-17 21:11
337 查看
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return
Note:
Could you optimize your algorithm to use only O(k) extra space?
C++代码:
For example, given k = 3,
Return
[1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
C++代码:
class Solution { public: vector<int> getRow(int rowIndex) { vector<int> row; row.push_back(1); for(int i=0;i<=rowIndex;i++) { vector<int> temp_row; row.push_back(0); int n=0; for(int j=0;j<=i;j++) { n+=row[j]; temp_row.push_back(n); n=row[j]; } row=temp_row; } return row; } };
相关文章推荐
- JAF框架及在JavaMail中的应用
- java 程序中try catch / throw / 函数名上throws 具体执行顺序和扔异常捕获异常的概念模型
- 安卓第四夜 概念漫游(下)
- Ubuntu 14.04 安装MongoDB社区版
- Linux Wget 命令
- 在类中delete自己会不会有问题??
- 安卓第三夜 概念漫游(上)
- wamp相关问题
- 输入名字或者地址可以下载论文
- Becoming a Hacker...
- (转)Java并发编程:volatile关键字解析
- shell脚本的#!
- 利用xShell 与linux进行文件互传
- 安卓第二夜 有趣的架构
- android顶部(toolbar)搜索框实现
- LINQ
- Mathematica中用有限元方法解不规则区域上的波动方程
- Spring web Flow2学习笔记
- 安卓第一夜 第一个应用
- 缓存淘汰算法--LRU算法