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, ...
随机推荐
- 两款高性能并行计算引擎Storm和Spark比較
对Spark.Storm以及Spark Streaming引擎的简明扼要.深入浅出的比較,原文发表于踏得网. Spark基于这种理念.当数据庞大时,把计算过程传递给数据要比把数据传递给计算过程要更富效 ...
- Android Studio设置行宽、格式化断行
设置基于Android studio 1.2,其它版本可能位置不大一样,可以直接搜索 1.设置行宽 就是那条右标准线的位置:Setting-->Editor-->Code Style,右侧 ...
- SVG Use(转)
转自:http://www.zhangxinxu.com/wordpress/2014/07/introduce-svg-sprite-technology/ 未来必热:SVG Sprite技术介绍 ...
- python DES3 加密解密
背景:想给公司的进件流程写一套进件脚本,首先遇到的就是加密解密.公司用的 DES3 + base64 加密解密 一.安装 pycrypto模块,推荐用pycrypto编译文件,直接下载安装就行 ht ...
- 使用Free命令查看Linux服务器内存使用状况(-/+ buffers/cache详解)
free命令可选参数 -b,-k,-m,-g show output in bytes, KB, MB, or GB -h human readable output (automatic unit ...
- linux环境配置时钟同步ntpd服务
配置: 服务器1:192.168.169.139 服务器2:192.168.169.140 服务器3:192.168.169.141 目的:NTP能与互联网的时间保持同步,而且本身也是一台NTP服务器 ...
- LINQ不包含列表
var query=lista.Where(p=>!listb.Any(g=>p.id==g.id && p.no==g.no))
- matlab出错及改正
1 使用小波分析时,出现下面错误: 错误使用 wavedec需要的 X 应为 矢量.出错 wavedec (line 34)validateattributes(x,{'numeric'},{'vec ...
- 名称空间(Namespaces)(转)
大致来说,命名空间只是将名称映射到对象的容器.正如你可能已经听到的,Python中的所有内容 - 字符串,列表,词典,函数,类等都是一个对象.这样的“名称与对象”的映射使我们能够通过分配给它的名称访问 ...
- [笔记]Go语言的字符串拼装方式性能对比
Go语言中字符串的拼装方法很多,那么问题来了,到底哪家性能好? 下面代码,分别比较了 fmt.Sprintf,string +,strings.Join,bytes.Buffer,方法是循环若干次比较 ...