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 ...
随机推荐
- FindLetter 类——查找文件中特定的字符,每一行开头为某一个字符,则跳过
/*统计除了>之外的行里面CHED四个字母总数*/ #include<fstream> #include<iostream> #include<cstring> ...
- python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客
python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客 python datetime模块strptime/strptime form ...
- JAVA之File类创建对象构造函数传参数需要注意的几点
java中File类用于创建一个文件对象. 首先看一段代码: 1. package MyText1; import java.io.File; public class MyText1 { publi ...
- hadoop 学习入门 一 云计算之旅
一. 什么是云计算: 云计算是分布式计算.网格计算.并行计算.效用计算.网络存储.负载均衡.虚拟化.网络计算等传统计算技术的融合体. 二. 云计算的核心技术: 1 编程模型 2 海量数据分布存储技术 ...
- Unity3D手游-横版ACT游戏完整源代码下载
说明: 这不是武林.这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图.让你来创造它的未来,剑魁道天下,一剑斗烛龙! ...
- Problem D: Flip Five
大致题意:3 * 3的黑白格,在翻转的时候会本身和四周的都翻转,问最小翻转几次变成全部是白色解题思路:把3 * 3 = 9 个格子进行全排列,然后穷举然后找翻转的最小次数 #include <i ...
- 移动端网页JS框架-手机触摸事件框架,日历框架带滑动效果
swiper.js,hammer.js,mobiscroll http://www.mobiscroll.com/ 日历
- session对象和applicatione对象
ASP.NET 的常用对象有:response对象.request对象.application对象.server对象.session对象.下面主要讨论session对象和cookie对象. sessi ...
- 关于iOS7以后版本号企业公布问题
大家都知道,苹果在公布7.1以后,不打个招呼就把企业公布方式给换掉了(谴责一下~) 曾经普通server+web页面+ipa+plist就能够搞定,如今已经不行了. 关于如今企业公布教程网上贴出来了非 ...
- Wayland中的跨进程过程调用浅析
原文地址:http://blog.csdn.net/jinzhuojun/article/details/40264449 Wayland协议主要提供了Client端应用与Server端Composi ...