[LeetCode118]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>> vec1;
for(int i = ; i < numRows; ++i)
{
vector<int> vec2;
vec2.push_back();
for(int j = ; j < i; ++j)
{
int tmp = vec1[i-][j-] + vec1[i-][j];
vec2.push_back(tmp);
}
if(i != )
vec2.push_back();
vec1.push_back(vec2);
}
return vec1;
}
};
[LeetCode118]Pascal's Triangle的更多相关文章
- 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- [leetcode-118]Pascal's triangle 杨辉三角
Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- LeetCode118. Pascal's Triangle 杨辉三角
题目 给定行数,生成对应的杨辉三角 思考 同一行是对称的,最大的下标为(行数+1)/2;1,1,2,3,6;下标从0开始,则对应分别为0.0.1.1.2.2 对于第偶数行,个数也是偶数,对于奇数行,个 ...
- [Swift]LeetCode118. 杨辉三角 | Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...
- LeetCode118:Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- [LeetCode] 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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
随机推荐
- sql server数据库保存图片或者其他小文件
原文:sql server数据库保存图片或者其他小文件 测试用sql server数据库保存图片或者其他小文件. 文件流字段用varbinary类型. static void Main() { App ...
- DOS批处理延时技术
DOS批处理延时技术 举个例子,我们要延时5秒打开gdh.txt这个文件,可以用以下几个方法 方法一:ping 缺点:时间精度为1秒,不够精确 www.2cto.com @echo off ...
- 设置SVN忽略文件和文件夹(文件夹)
在多数项目中你总会有文件和文件夹不须要进行版本号控制.这可能包含一些由编译器生成的文件,*.obj,*.lst,也许是一个用于存放可运行程序的输出文件夹.仅仅要你提交改动,TortoiseSVN 就会 ...
- JQuery是继prototype之后又一个优秀的Javascript库
JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...
- Qt调用word 例子
Qt调用word 例子 Getting Microsoft Word Object to SaveAs #include <QtGui> #include <QAxObject> ...
- mysql 开放的telnet
两步开幕mysql远程连接 一个,登录mysql # mysql -uroot -p 两,配置远程连接 mysql > GRANT ALL PRIVILEGES ON *.* TO 'user1 ...
- jQuery获取url参数值
$.extend({ getUrlVars: function () { var vars = [], hash; var hashes = window.location.href.slice(wi ...
- Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,相似图片浏览器
MAC : XCode -> Scroll View 控件以Thumbnail的方式显示一个目录的全部图片,类似图片浏览器 STEP1:将两个目录复制到project里面ImageBrowser ...
- 教你pomeloclient包libpomelo增加cocos2d-x 3.0工程(Windows、Android、IOS平台)
Windows平台 操作系统:Windows7(64-bit) VS版本号:2013 Cocos2d-x版本号:3.0 project路径:E:\cocos2d-prj\ 1.从github下载lib ...
- 《Javascript高级程序设计》读书笔记之闭包
闭包 function createComparisonFunction(propertyName) { return function (object1, object2) { var value1 ...