leetcode-Pascal's Triangle II
2015-11-06 19:30
417 查看
Difficulty:
Easy
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) { if(rowIndex<0) return vector<int>(); if(rowIndex==0) return {1}; vector<int> ores(2,1); if(rowIndex==1) return ores; for(int i=1;i<rowIndex;++i){ vector<int> res; res.push_back(1); int osize=ores.size(); for(int i=0;i<osize-1;++i) res.push_back(ores[i]+ores[i+1]); res.push_back(1); ores=res; } return ores; } };
相关文章推荐
- POJ 3254 【状态压缩DP】
- 树以及树的遍历和搜索
- CSS-伪元素
- UI界面-线性布局
- freemarker的使用以及认识
- SQLiteDatabase单例模式
- 数电和模电比较
- mysql宽字符注入
- HDU_1043 Eight
- poj 1220 NUMBER BASE CONVERSION 【栈】
- HDOJ 5547 Sudoku (DFS 数独填数+回溯)
- ASLA Codec架构
- 《现代操作系统》读书笔记---进程与线程篇
- JavaScrip单选,下拉框,文本框取值赋值--【DRP】
- 【leetcode】【96】Unique Binary Search Trees
- 又见KeepAlive
- GBK 编码时 url 中带中文参数的问题
- JQ的each
- OpenCV - win7+vs2013(2012)+opencv3.0.0 环境配置 (以及配置技巧)
- ashx页面中 Session值出现“未将对象引用设置到对象的实例”错误