leetcdoe 帕斯卡尔三角形2 Pascal's Triangle II
2015-08-13 14:37
369 查看
帕斯卡尔三角形:
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
class Solution { public: vector<int> getRow(int rowIndex) { vector<vector<int>> res(rowIndex+1); //if(rowIndex<0)return res[0]; res[0].push_back(1); int i,j; for(i=1;i<res.size();i++) { for(j=0;j<i+1;j++) {if(j==0||j==i)res[i].push_back(1); else res[i].push_back(res[i-1].at(j-1)+res[i-1].at(j)); } } return res[rowIndex]; } };
相关文章推荐
- 如何总结和整理学术文献?
- BZOJ 1047 [HAOI2007]理想的正方形
- sql comm
- HDU ACM 2008 数值统计
- 数据库出现ORA-00283/ORA-01610的问题
- iOS中关于登录验证方面的问题的解决
- HDU 1004 Let the Balloon Rise (map使用)
- 详解EBS接口开发之库存事务处理-物料批次导入
- 修改mysql数据库root用户的密码
- Groovy 数据库应用开发实践-SQL对象托管和封装
- 设计模式:26 项目多也别傻做_享元模式
- 通过boost::bind实现c++多线程
- 获取公网IP
- Exceptions不能跨进程catch
- 64-bit Itanium与x64
- mac系统Sublime 2 乱码问题
- C++常用字符串分割方法实例汇总
- 修改fiddler中CustomRules.js的Request或Response
- USB枚举过程
- unable to instantiate activity...