Leetcode Problem.118—Pascal's Triangle
2015-06-03 15:25
337 查看
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
My C++ solution!
For example, given numRows = 5,
Return
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
My C++ solution!
vector<vector<int>> generate(int numRows) { vector<vector<int>>result; result.resize(numRows); if(numRows==0) return result; if(numRows==1) { result[0].assign(1,1); return result; } if(numRows>=2) { result[0].assign(1,1); for(int i=1;i<numRows;i++) { vector<int>pre(result[i-1]); vector<int>temp; temp.resize(i+1); temp[0]=1; for(int j=1;j<i/2+1;j++) { temp[j]=pre[j-1]+pre[j]; } for(int j=i/2+1;j<i+1;j++) { temp[j]=temp[i-j]; } result[i]=temp; } } return result; }
相关文章推荐
- UITableView 横向滚动(二)
- leetcode:Roman to Integer and Integer to Roman
- DataBase 之 实用积累
- Leetcode Problem.88 —Merge Sorted Array
- Oracle 11gR2 使用RMAN Duplicate复制数据库
- Windows GetAsyncKeyState(vk_code)
- NETBIOS协议
- DRUID连接池的使用
- springmvc下的基于token的防重复提交
- Java软件开发中的几种认识误区
- Leetcode Problem.83—Remove Duplicates from Sorted List
- ueditor富文本
- C++中const、volatile、mutable的用法
- 基于DRBD实现高可用MariaDB
- Centos6.6上rsyslog一些用法和扩展
- Some paper related to Image Deblurring
- switch语句中得case
- linux centos6.5安装KVM
- RDIFramework.NET ━ .NET快速信息化系统开发框架钜献 V2.9 版本震撼发布
- 异常日志以及非异常日志记录方法