LeetCode_pascals-triangle
2015-09-13 12:07
316 查看
https://leetcode.com/problems/pascals-triangle/
解题思路:第二行起,上一行的两个数之和作为下一行的一个数;
解题思路:第二行起,上一行的两个数之和作为下一行的一个数;
class Solution { public: vector<vector<int>> generate(int numRows) { vector<int> up(2,1); vector<int> down(1,1); vector<vector<int>> floor; if(numRows == 1){ floor.push_back(down); return floor; } if(numRows == 0){ return floor; } floor.push_back(down); floor.push_back(up); int sum; for(int i = 2;i < numRows;i++){ for(int j = 1;j < up.size();j++){ sum = up[j] + up[j-1]; down.push_back(sum); } down.push_back(1); floor.push_back(down); up.assign(down.begin(),down.end()); down.clear();//注意,要清空数组; down.push_back(1);//返回的原始状态 } return floor; } };
相关文章推荐
- 使用apktool + idea 调试smali
- kick start 无人值守安装Linux
- maven 使用
- 网络连接之——HttpClient(doGet和doPost)
- 年总结(三):风雨征程一年机房路
- poj 3252 Round Numbers
- mysql中join的四种连接
- 斯坦福Developing iOS 8 Apps学习笔记(五)
- Matlab实时监控股票交易数据之Timer函数应用实例
- 【软考视频基础知识】——数据结构
- 在BootStrap的modal中使用Select2
- java
- 在windows server 中批量绑定ip和mac的方法
- 小说阅读器,伪装360加速器
- week1-10Theory of algorithms
- 教你识别简单的免查杀PHP后门
- 回望英语-7
- html5+css3
- 剑指Offer面试题:28.连续子数组的最大和
- [LeetCode#253] Meeting Rooms II