题目:

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的更多相关文章

  1. 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  2. [leetcode-118]Pascal's triangle 杨辉三角

    Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  3. LeetCode118. Pascal's Triangle 杨辉三角

    题目 给定行数,生成对应的杨辉三角 思考 同一行是对称的,最大的下标为(行数+1)/2;1,1,2,3,6;下标从0开始,则对应分别为0.0.1.1.2.2 对于第偶数行,个数也是偶数,对于奇数行,个 ...

  4. [Swift]LeetCode118. 杨辉三角 | Pascal's Triangle

    Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...

  5. LeetCode118:Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  6. [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, ...

  7. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  8. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  9. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

随机推荐

  1. hdu4738(双连通分量)

    传送门:Caocao's Bridges 题意:n个岛,曹操在一些岛之间建了一些桥,每个桥上有一些士兵把守,周瑜只有一个炸弹只能炸掉一个桥,并能使一些岛被孤立出来,炸弹需要士兵带过去,士兵的数量不能小 ...

  2. OC 获取城市首字母

    解析依据文件中面的内容,读入一个城市,输出所在首字母 比方读入 长春 输出 c 读入 北京 输出 b 不知道文本中的字体是什么格式 读取文件时 程序不能正确执行 运用oc中的字典 initWithOb ...

  3. 检查Linux Bash安全漏洞以及各环境修复解决方法

    第一.检测是否存在Bash漏洞$env x='() { :;}; echo vulnerable' bash -c "echo this is a test"如果返回以下内容:则请 ...

  4. https原理及tomcat配置https方法

    一. 什么是HTTPS 在说HTTPS之前先说说什么是HTTP,HTTP就是我们平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不 ...

  5. xcode多target

    原文:http://www.codza.com/free-iphone-app-version-from-the-same-xcode-project There are more than 15,0 ...

  6. Linux mysql 数据库忘记root密码

    1.修改MySQL的登录设置: # vi /etc/my.cnf 1在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi. 2.重新启动mysqld # /etc/i ...

  7. 怎样改动SVN的地址

    改动svn地址的目的有两个,一个是更改默认svn路径.还有一个就是svn库server迁移了. 我碰到的是另外一种情况,SVN的IP地址改了,须要这么切换: 在本地配置库副本根文件夹点击鼠标右键--& ...

  8. VS2010升级VS2013后,出现没有定义类型“PowerPacks.ShapeContainer”错误解决方法

    开发说明: http://msdn.microsoft.com/zh-tw/library/microsoft.visualbasic.powerpacks.aspx Microsoft.Visual ...

  9. plist文件读写

    - (void)viewDidLoad { [super viewDidLoad]; NSDictionary *dictionary1 = [NSDictionary dictionaryWithO ...

  10. centos一些命令

    1.查看系统使用端口并释放端口 [root@my_nn_01 WEB-INF]# lsof -w -n -i tcp:80 COMMAND   PID USER   FD   TYPE DEVICE ...