题目:

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>> vec1;for(int i = 0; i < numRows; ++i){vector<int> vec2;vec2.push_back(1);for(int j = 1; j < i; ++j){int tmp = vec1[i-1][j-1] + vec1[i-1][j];vec2.push_back(tmp);}if(i != 0)vec2.push_back(1);vec1.push_back(vec2);}return vec1;}
};

[LeetCode118]Pascal's Triangle相关推荐

  1. 帕斯卡三角形(Pascal's triangle)

    // The following code is compiled on VC2005 // #include "stdafx.h" /*--------------------- ...

  2. [leedcode 118] Pascal's Triangle

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

  3. Leetcode 118:Pascal's Triangle 杨辉三角

    118:Pascal's Triangle 杨辉三角 Given a non-negative integer numRows, generate the first numRows of Pasca ...

  4. 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 ...

  5. LeetCode Pascal's Triangle

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

  6. 119. Pascal's Triangle II (Graph; WFS)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  7. 【LeetCode从零单排】No118 Pascal's Triangle

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

  8. [Array]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. C++Pascal‘s Triangle杨辉三角的实现算法

    C++Pascal's Triangle杨辉三角的实现算法 C++Pascal's Triangle杨辉三角的实现算法完整源码(定义,实现,main函数测试) C++Pascal's Triangle ...

最新文章

  1. linux下定时器实现
  2. char类型是多少 mat_这轮面试,居然只有20%的人了解 MAT 神器
  3. Index of c#
  4. 获取不到时间_一月自考成绩查询时间一出,看了文章这次稳过
  5. sunday java_Sunday算法:最快的字符串匹配算法
  6. MobX 上手指南,写 Vue 的感觉?
  7. “入乡随俗,服务为主” 发明者量化兼容麦语言啦!
  8. php object oriented,PHP学习记录之面向对象(Object-oriented programming,OOP)基础【接口、抽象类、静态方法等】...
  9. 天正双击墙体不能编辑_今日设计分享:CAD常用快捷键、Ps快捷键大全、天正快捷键总结!...
  10. SpringBoot2.0 整合 Dubbo框架 ,实现RPC服务远程调用
  11. Hessian学习(springboot环境)
  12. Atitit cs计算机科学概论 艾提拉解读版 2. 第二部分 信息层 4 5. 第三部分 硬件层 5 8. 第四部分 程序设计层 7 13. 第五部分 操作系统层 10 16. 第六部分 应
  13. java修改注册表_Java的Windows安装程序对注册表的修改
  14. 各个音阶的频率_声音各个频率的还原
  15. 现身说法:37岁老码农找工作!
  16. 阿里大数据产品Dataphin上线公共云,将助力更多企业构建数据中台
  17. P1903 数颜色 (带修莫队)
  18. 常用颜色的RGB分布
  19. App Widgets 详解四 RemoteViews、RemoteViewsService和RemoteViewsFactory
  20. SSM餐饮管理点餐系统

热门文章

  1. java 文件名 类名_java文件名为什么要与类名相同
  2. 关闭 启动_win10系统关闭快速启动功能教程
  3. python从大到小排序_python作业:用嵌套的列表存储学生成绩数据,并编程完成如下操作...
  4. java分库校验商户流水号是否重复,asp中用数据库生成不重复的流水号
  5. gitlab 删除仓库
  6. C语言 底层IO readwrite
  7. python input sys.stdin
  8. matplotlib.pyplot.bar()条形图
  9. Linux线程同步介绍和示例
  10. 怎么用python爬图片_如何用Python来制作简单的爬虫,爬取到你想要的图片