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. 让黑白的SecureCRT彩色起来

    让黑白的SecureCRT彩色起来,如图仿真设置如下:  

  2. Nginx 设置rewrite规则是遇到的一个{}大括号引发的报错问题

    一个群友提到: 用nginx image_filter模块裁图,用!拼宽高能够实现,现在想用参数传宽高总是报错,配置如下:   location ~ ^/images/.* {     if ( $q ...

  3. 学习ThinkPHP第一天

    今天开始学习PHP框架了,刚开始学,感觉挺兴奋的,离自己建立自己的博客又仅了一步,在linux环境下配置一定要赋予新创建的文件夹权限: sudo chmod -R 0777   filePath 这样 ...

  4. BZOJ2938: [Poi2000]病毒(AC自动机)

    2938: [Poi2000]病毒 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1678  Solved: 849[Submit][Status][D ...

  5. php 双引号字符串里包变量的用法

    第一种 $ary['a'] 去掉单引号$ary = array('a'=>1);$b = 5; $str = "fdsfdsf$ary[a]";$str = "fd ...

  6. macOS -- 如何通过终端开启/关闭SSH

    在macOS中(较新版),基本都会配置了SSH,能完成我们开发中绝大部分功能,所以不需要再去使用第三方的软件去操作. 不过SSH守护进程是默认禁用的,我们需要手动开启 1. 查看是否开始SSH功能 s ...

  7. Spring Bean单例与线程安全

    一.Spring单例模式及线程安全 Spring框架中的Bean,或者说组件,获取实例的时候都是默认单例模式,这是在多线程开发的时候需要尤其注意的地方. 单例模式的意思是只有一个实例,例如在Sprin ...

  8. lvds cable信号

    http://forums.bit-tech.net/showthread.php?t=208616

  9. sublime text 3 配置优化

    1.在用Sublime里编写代码时,需要把TAB键转换成四个空格. 菜单栏里点击:首选项-> 设置-用户(Preferences-> Setting-User)在弹出来的文本里,添加如下两 ...

  10. IntelliJ IDEA 基础设置

    原文地址:IntelliJ IDEA 基础设置 博客地址:http://www.extlight.com 一.前言 IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,Intel ...