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 ...
随机推荐
- arm-linux-gcc下载与安装
在RHEL 5平台上安装配置arm-linux-gcc 2011-02-23 19:35:40| 分类: 嵌入式开发环境 | 标签: |字号大中小 订阅 . 在linux平台上安装好的基础上,开 ...
- N-Queens And N-Queens II [LeetCode] + Generate Parentheses[LeetCode] + 回溯法
回溯法 百度百科:回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步又一次选择,这样的走不通就退回再走的技术为回溯法 ...
- 安装Oracle时可能碰到的常见问题-1
安装Oracle可能有些人觉得是一件非常easy的事情,但事实上是在安装的过程中蕴含着丰富的知识点.尤其安装在Linux平台,可能会碰到这样或那样各种诡异的问题,透过问题看到本质,这才是从深处理解Or ...
- JS - 图片放大器
下载地址:http://www.lanrentuku.com/js/tupian-1170.html
- 【ASP.NET Web API教程】2.1 创建支持CRUD操作的Web API
原文 [ASP.NET Web API教程]2.1 创建支持CRUD操作的Web API 2.1 Creating a Web API that Supports CRUD Operations2.1 ...
- System Request 进入KDB模式过程详解
0 echo g > /proc/sysrq-trigger 怎么让系统停下来,进入进入KDB循环? 1 需要简单了解下:Linux Magic System Request 2 ...
- 百度贴吧客户端(Android)网络通信行为分析
百度贴吧安卓客户端网络通信行为分析 本文由CSDN-蚍蜉撼青松[主页:http://blog.csdn.net/howeverpf]原创,转载请注明出处! 一.实验环境与结果概述 1.1 实验环境 ...
- 【Unity3D自学记录】Unity3D网络之Socket聊天室初探
首先创建一个服务端程序,这个程序就用VS的控制台程序做即可了. 代码例如以下: using System; using System.Collections.Generic; using System ...
- 14.3.2.3 Consistent Nonlocking Reads 一致性非锁定读
14.3.2.3 Consistent Nonlocking Reads 一致性非锁定读 一致性读 意味着 InnoDB 使用多版本来保护查询一个数据库在当前时间点的快照. 查询看到被事务做出的修改, ...
- HTTP POST请求的Apache Rewrite规则设置
最近自测后端模块时有个业务需求需要利用WebServer(我用的是Apache)将HTTP POST请求转发至后端C模块,后端处理后返回2进制加密数据.http post请求的url格式为: ...