Pascal's Triangle II
2015-12-09 12:37
288 查看
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?
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) { vector<int> result(rowIndex+1); result[0] = 1; for(int i=1;i<=rowIndex;i++){ for(int j=i;j>0;j--){ if(j == i){ result[j] = result[j-1]; }else{ result[j] = result[j] + result[j-1]; } } } return result; } };
相关文章推荐
- haproxy转发真实IP给web
- linux: /usr/bin/ld: cannot find -lloc
- 蓝桥杯 01字串(循环)
- Neutron中的Quota
- 创建虚拟机libvirt报错 Fail bind socket:Permission Deny
- Visual Studio 2015初体验——前端开发工作的问题
- 分享一下我封装iOS自定义控件的体会,附上三个好用的控件Demo <时间选择器&多行输入框&日期选择器>
- 报表模型单元格的引用-报表系统
- war包部署时获取绝对路径问题
- 音频帧概念详解
- 我学习与领悟的工匠精神
- Cacti部署过程
- 使用explain分析sql语句
- js createElement appendChild createTextNode用法
- Linux学习笔记(十九、别名与快捷键)
- CryptoJS & JAVA AES加密、解密
- 也说软件测试用例
- 常用DOS命令(二)-- CD命令
- Ironic的安装那些事儿
- Padding与Margin之间的区别