leetcode - 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:
std::vector<std::vector<int> > generate(int numRows) {
std::vector<int> vec;
std::vector<std::vector<int>> res(numRows,vec);
int triangle[100][100];
for (int i = 0; i < numRows; i++)
{
triangle[i][0] = 1;
triangle[i][i] = 1;
}
for (int i = 2; i < numRows; i++)
{
for (int j = 1; j < i + 1; j++)
{
triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];
}
}
for (int i = 0; i < numRows; i++)
{
for (int j = 0; j <= i; j++)
{
res[i].push_back(triangle[i][j]);
}
}
return res;
}
};
leetcode - Pascal's Triangle的更多相关文章
- LeetCode——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 II
题目:给定一个行索引index,返回帕斯卡三角形第index层的三角形 算法:生成index层帕斯卡三角形,并返回第index层三角形 public class Solution { public L ...
- 【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】118. Pascal's Triangle
@requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](http ...
- leetcode笔记:Pascal's Triangle
一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- leetcode:Pascal's Triangle
一. 题目 经典题目,杨辉三角,输入行数.生成杨辉三角的数组. 二. 分析 首先,我们知道有例如以下规律: 1.每一行的第一个数和最后一个数都为1 2.中间的数是上面数和上面数左边的数 ...
- Pascal's Triangle I,II
题目来自于Leetcode https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numR ...
- 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 ...
随机推荐
- prevPage / nextPage in jQuery Mobile | George Nixon's Blog
prevPage / nextPage in jQuery Mobile | George Nixon's Blog ui.prevPage[0].id I finally worked this o ...
- Ubuntu下安装ADT(图文教程)
个人感觉Ubuntu下安装ADT跟在Windows大同小异 一.装上JDK和Eclipse 如果还没有装上的,请参考我前面的博文: http://blog.csdn.net/ljphhj/articl ...
- pygame编写贪吃蛇
一直想用pygame做一个小游戏的,可是因为拖延症的缘故一直没有动,结果那天看到了一个12岁的国际友人小盆友用pygame做的一款塔防游戏,突然感觉已经落后超级远了,所以心血来潮做小游戏了.高中陪伴我 ...
- 关于CopyU!的常见问题解答
拷优(CopyU!)常见问题解答 本常见问题解答列举了一些常见的疑问及其解释,如果您对CopyU!有任何问题,请您首先查看本解答! 本解答将会保持随时更新! 一.使用篇: 1.问:我的杀毒软件 ...
- ASP.NET - 记录错误日志
不需要像log4net/Nlog/Common Logging配置,简单好用. 不用增加声明logger对象,可记录当前执行状况. 可以定义 维护功能模板的开发人员,以便用功能模块对于开发人员. 出处 ...
- 嵌入式Linux常见问题
Linux问题集 1 linux设置环境变量及保存地点 1. 显示环境变量HOME $ echo $HOME /home/terry 2. 设置一个新的环境变量WELCOME $ exportWELC ...
- win7+Powerpoint2007下设置演讲者视图,两步搞定
步骤1: 步骤2: 这样,你就可以对着ppt的备注讲解了,且用户看不到你的备注以及你的电脑桌面.cool!
- C#控件系列--文本类控件
C#控件系列--文本类控件 文本类控件主要包含Label.LinkLabel.Button.TextBox以及RichTextBox. Label 功能 Label用来 ...
- 使用Xcode无法发布程序(Archive按钮一直为灰色不可点击)
问题现象:想在Xcode中把代码编译发布成ipa程序,但“Product”->“Archive”按钮一直不可使用. 解决办法:目前的运行配置是使用模拟器,改成“iOS Device”即可 ...
- Android CTS 结果 testResult.xml 修改 fail 项 为 notExecuted 项 分析
这两天一直在搞 Android 4.1 CTS ,每次完整跑完一遍后总有几百项 failed,用编辑器手动改为 notExecuted 项后重新跑,有很多项第二次都跑过了. 但是发现直接修改也带来很多 ...