LeetCode OJ:Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
帕斯卡三角,很简单的问题,见代码:
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ret;
vector<int> tmpVec;
ret.clear();
tmpVec.clear();
for(int i = ; i < numRows; ++i){
if(i == ){
tmpVec.push_back();
}else{
for(int j = ; j <= i; ++j){
if(j == ) tmpVec.push_back();
else if(j == i) tmpVec.push_back();
else tmpVec.push_back(ret[i - ][j - ] + ret[i - ][j]);
}
}
ret.push_back(tmpVec);
tmpVec.clear();
}
return ret;
}
};
LeetCode OJ:Pascal's Triangle(帕斯卡三角)的更多相关文章
- LeetCode OJ——Pascal's Triangle II
http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algo ...
- LeetCode OJ——Pascal's Triangle
http://oj.leetcode.com/problems/pascals-triangle/ 杨辉三角 先分析数据,找出规律 ans[row][col] = ans[row-1][col-1]+ ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- [Leetcode][JAVA] Pascal's Triangle I, II
Pascal's Triangle: Given numRows, generate the first numRows of Pascal's triangle. For example, give ...
- Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- LeetCode 119. Pascal's Triangle II (杨辉三角之二)
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
随机推荐
- mysql如果主库宕机,如何解决?
两种情况服务器down机,数据库down机 如果此时需要切从库 1.先show processlist\G,查看状态 如果看到两个状态,说明此时的从库和主库是同步的 state: waiting fo ...
- 解决hash冲突的办法
1.开发定址法 2.再哈希法 3.链地址法 4.建立一个公共溢出区
- Java全局变量
全局变量:Java程序中,不能在所有类之外定义全局变量,只能通过在一个类中定义公用.静态的变量来实现一个全局变量.例如:ClassGlobalVar{public static global_var; ...
- 从零到一创建ionic移动app:基础开发环境搭建
myAPP项目是在Ubuntu14.04下创建 本项目开发node 4.5/cordova 6/ionic 2 第一步 安装nodejs npm install -g n n v4.5.0 使 ...
- 你真的会用javascript?
偶然在csdn看到几个js的小题,考察的都是很基础的知识,拿来分享一下1. 1 2 3 4 if (!("a" in window)) { var a = 1; } alert(a ...
- flex NaN
如果该值为NaN(非数字),则返回true:否则返回false.public function isNaN(num:Number):Boolean 举例:NaN值不是int或uint数据类型的成员.f ...
- 关于Webpage Not Found问题解决~~~
还是外文网站好,以下解决办法: IIS6.0 UI vs. IIS 7.x UI Series: More about Web Service Extensions This week in the ...
- poj2092
/*水题,算每个号码处出现的次数*/ #include<stdio.h> #include<string.h> #include<algorithm> using ...
- Windows 2008下系统网站运行环境的搭建
1.右击[计算机]-->[管理],进入到”服务器管理器” 界面,如图所示: 2.依次展开[角色]-->[Web服务器(IIS)]-->[Internet 信息服务(IIS)管理器], ...
- python3爬虫全国地址信息
PHP方式写的一团糟所以就用python3重写了一遍,所以因为第二次写了,思路也更清晰了些. 提醒:可能会有502的错误,所以做了异常以及数据库事务处理,暂时没有想到更好的优化方法,所以就先这样吧.待 ...