leetcode 119 Pascal's Triangle II
2016-06-11 14:55
357 查看
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?
Subscribe to see which companies asked this question
For example, given k = 3,
Return
[1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
Subscribe to see which companies asked this question
class Solution { public: vector<int> getRow(int rowIndex) { vector<int> vec; if(rowIndex < 0) return vec; int prev = 0; for(int i=0; i <= rowIndex; i++) { if(i==0) vec.push_back(1); for(int j=vec.size()-1; j > 0; j--) { vec[j] = vec[j]+vec[j-1]; } if(i > 0) vec.push_back(1); } return vec; } };
相关文章推荐
- git基础使用
- 标准采购订单的计算方案确定
- iOS开发多线程篇—多线程简单介绍
- ASP.NET 搭建贴吧机器人(零)
- JS定时器使用,定时定点,固定时刻,循环执行详解
- 4年程序员
- 第16天内容
- XILINX的FPGA的资源
- Audit by access VS by session
- openwrt config_gen Makefile
- 第七届acm省赛总结
- word chains ruby
- jQuery easyui datagrid pagenation 的分页数据格式
- Python入门:中file.seek函数的用法
- 【Get深一度】关于JCR期刊影响因子分区
- 给差生一点时间,让他变成你喜欢的样子
- 第15周项目2--洗牌
- Mysql操作符号
- jquery JSON的解析方式
- Range——克隆对象,cloneRange()