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>> result(numRows, vector<int>());
if(numRows == ) return result;
result[].push_back();
for(int i =; i < numRows; i++)
{
result[i].push_back();
for(int j = ; j<i;j++)
{
result[i].push_back(result[i-][j-]+result[i-][j]);
}
result[i].push_back();
}
return result;
}
};

118. Pascal's Triangle (Array)的更多相关文章

  1. Leetcode#118. Pascal's Triangle(杨辉三角)

    题目描述 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2, ...

  2. 118. Pascal's Triangle

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

  3. LN : leetcode 118 Pascal's Triangle

    lc 118 Pascal's Triangle 118 Pascal's Triangle Given numRows, generate the first numRows of Pascal's ...

  4. leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle

    118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...

  5. LeetCode Array Easy 118. Pascal's Triangle

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

  6. LeetCode 118. Pascal's Triangle (杨辉三角)

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

  7. LeetCode 118 Pascal's Triangle

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

  8. [LeetCode]题解(python):118 Pascal's Triangle

    题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...

  9. leetcode 118 Pascal's Triangle ----- java

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

随机推荐

  1. 流程设计器jQuery + svg/vml(Demo3 - 添加流程结点)

    经过前面的准备工作,终于把设计器的主要UI界面搭建好了,接下来到添加流程结点,效果如下图 代码:GoFlow_03.zip 演示地址:Demo 微信演示公众号: 另:Silverlight版 Silv ...

  2. java基础第8天

    继承extends(也叫扩展) 多个类中存在相同的属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需再定义这些属性和行为,只要继承那个类即可. 通过extends关键字可以实现类的继承 继承的 ...

  3. openGL之着色器程序的使用

    #define GLEW_STATIC #include <GL\glew.h> #include <GLFW\glfw3.h> #include<iostream> ...

  4. SUSE Linux Enterprise Server设置IP地址、网关、DNS(转载)

      说明: ip:192.168.21.172 子网掩码:255.255.255.0 网关:192.168.21.2 dns:8.8.8.8 8.8.4.4 1.设置ip地址vi /etc/sysco ...

  5. Linux运维学习笔记-文件系统知识体系总结

    文件系统知识总结 新买的硬盘要存放数据需要怎么做? 首先将硬盘装机做RAID,做完RAID后进行分区,分完区后格式化创建文件系统,最后存放数据. 硬盘的内外部结构: 物理形状: 接口类型: IDE(I ...

  6. EM算法的思考

    参考文献1: http://blog.sina.com.cn/s/blog_6c7b434d01013zwe.html 参考文献2: http://www.cnblogs.com/jerrylead/ ...

  7. Codeforces 990B :Micro-World

    B. Micro-World time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  8. ambassador 学习二 认证

    ambassador 可以在请求路由之前进行认证处理,一般的我们可能会使用第三方的认证服务 基本的环境安装可以参考相关文档 安装&&运行qotm 服务 可以参考官方文档,或者https ...

  9. hdu 4336 Card Collector——最值反演

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...

  10. 黄聪:WordPress 多站点建站教程(三):主站如何调用子站的文章内容、SQL语句如何写?

    1.如果懂得编程的朋友可以SQL语句,然后加上PHP函数等操作就可以通过直接调用网站的数据库信息来实现想要达到的目的. 既然要用到SQL语句首先得对WordPress多站点数据库有一个了解,多站点激活 ...