题意:给一个数字,返回一个二维数组,包含一个三角形。

思路:n=0、1、2都是特例,特别处理。3行以上的的头尾都是1,其他都是依靠上一行的两个数。具体了解Pascal三角形原理。

 class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector<vector<int> > ans;
if(!numRows) return ans;
vector<int> tmp;
tmp.push_back();ans.push_back(tmp);if(numRows==) return ans;
tmp.push_back();ans.push_back(tmp);if(numRows==) return ans; for(int i=; i<numRows; i++)
{
tmp.clear();
tmp.push_back();
for(int j=; j<i; j++)
{
tmp.push_back( ans[i-][j-]+ans[i-][j] );
}
tmp.push_back();
ans.push_back(tmp);
}
return ans;
}
};

Pascal's Triangle

LeetCode Pascal's Triangle Pascal三角形的更多相关文章

  1. 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II

    118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  2. LeetCode Pascal's Triangle && Pascal's Triangle II Python

    Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...

  3. 28. Triangle && Pascal's Triangle && Pascal's Triangle II

    Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...

  4. Pascal's Triangle,Pascal's Triangle II

    一.Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, giv ...

  5. 118 Pascal's Triangle 帕斯卡三角形 杨辉三角形

    给定 numRows, 生成帕斯卡三角形的前 numRows 行.例如, 给定 numRows = 5,返回[     [1],    [1,1],   [1,2,1],  [1,3,3,1], [1 ...

  6. LeetCode OJ:Triangle(三角形)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  7. 【LeetCode】118. Pascal's Triangle 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

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

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

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

随机推荐

  1. YOLO3训练widerface数据集

    因为YOLO3速度精度都很棒,所以想训练一下人脸模型,废话不多,进入正题 1写所有的配置文件 1.1 YOLO3-face.cfg 个人感觉YOLO的配置文件骑士和caffe差不多 在cfg/YOLO ...

  2. 如何在模板类中使用这些point类型?

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=271 由于PCL模块较多,并且是一个模板库,在一个源文件里包含很多PCL算法 ...

  3. this解惑

    前言 要正确理解this,首先得理解执行上下文,这里推荐汤姆大叔的执行上下文,因为this是在运行代码时确认具体指向谁,箭头函数除外. 全局作用域中的this node: 每个javaScript文件 ...

  4. GO:字符串Slice后乱码问题

    遇到的问题:用Slice 直接截取字符串的时候会出现乱码现象 package main import ( "fmt" ) func main() { str := "我的 ...

  5. [Xcode 实际操作]六、媒体与动画-(7)遍历系统提供的所有滤镜

    目录:[Swift]Xcode实际操作 本文将演示系统到底提供了多少滤镜供开发者使用,并了解每个滤镜都有哪些参数需要配置. 在项目导航区,打开视图控制器的代码文件[ViewController.swi ...

  6. redis单机上部署集群

    一.安装单机redis  redis的安装:版本至少是3.2.8及其以上,这里以3.2.8版本为例说明 1.安装redis wget http://download.redis.io/releases ...

  7. plsql developer 执行sql 文件

    用 Command Window,执行 @'sql file path' 注意,上面sql文件路径要加单引号

  8. react-native-syan-image-picker的使用

    传送门 第一种方式:link 第一步:安装 1.  npm install react-native-syan-image-picker --save 2.  react-native link re ...

  9. 洛谷 P1434 [SHOI2002]滑雪 解题报告

    这题方法有很多, 这里介绍2种: 方法1 很容易想到搜索, bfs或dfs应该都可以, 就不放代码了: 方法2 这题还可以用 dp 来做. 做法:先将每个点按照高度从小到大排序,因为大的点只能向小的点 ...

  10. 一个线性表中的元素为整数,设计一个算法,将正整数和负整数分开,使线性表的前一半为负整数,后一半为正整数。(C语言)

    以下为完整可运行示例代码: #include <stdio.h> #include <stdlib.h> typedef struct LNode{ int data; str ...