118. Pascal’s Triangle
My Submissions QuestionEditorial Solution
Total Accepted: 80029 Total Submissions: 241495 Difficulty: Easy
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]
]
Subscribe to see which companies asked this question

大概是考察用 vector 创建二维数组的应用:

class Solution {
public:vector<vector<int>> generate(int numRows) {vector<vector<int>> v(numRows);if(numRows == 0)return v;for(int i = 0; i < numRows; i++) {v[i].resize(i + 1);}v[0][0] = 1;if(numRows == 1)return v;v[1][0] = 1;v[1][1] = 1;for(int i = 2; i < numRows; i++) {v[i][0] = 1;v[i][i] = 1;}for(int i = 2; i < numRows; i++) {for(int j = 1; j < i; j++) {v[i][j] = v[i - 1][j - 1] + v[i - 1][j];}}return v;}
};

LeetCode 118. Pascal’s Triangle相关推荐

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

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

  2. LeetCode 118 Pascal's Triangle(帕斯卡三角形)(vector)

    翻译 给定一个行数字,生成它的帕斯卡三角形.例如,给定numRows = 5, 返回: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1] ] 原文 Given numR ...

  3. [LeetCode] 118. Pascal's Triangle Java

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

  4. No.118 Pascal's Triangle ||

    No.118 Pascal's Triangle || Given an index k, return the kth row of the Pascal's triangle. For examp ...

  5. LeetCode - Easy - 118. Pascal‘s Triangle

    Topic Array Description https://leetcode.com/problems/pascals-triangle/ Given a non-negative integer ...

  6. leetcode python3 简单题118. Pascal's Triangle

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十八题 (1)题目 英文: Given a non-negative int ...

  7. [LeetCode]--118. Pascal#39;s Triangle

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

  8. [LeetCode]119.Pascal's Triangle II

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/SunnyYoona/article/details/43562603 题目 Given an ind ...

  9. [leedcode 118] Pascal's Triangle

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

最新文章

  1. php数组重复值销毁,如何从PHP中删除数组中的重复值
  2. SpringSecurity权限表达式
  3. 802.11协议中的广播与tcp/ip中的广播
  4. iOS---A valid provisioning profile for this executable was not found
  5. 主表如何统计在附表中的出现次数?
  6. boost::phoenix::val相关的测试程序
  7. 计算机资源管理器课件,计算机基础课件ppt-第5讲控制面板与资源管理器.pdf
  8. 前端学习(2433):创建页面组件
  9. node模块加载机制。
  10. java中复选框组件_Java Swing JCheckBox:复选框组件
  11. 摸底10余家一线互联网公司大数据架构图:Hadoop渗透力太强!
  12. linux内存映射对开发版刷屏,TQ6410/OK6410裸机LCD刷屏程序借助UBOOT来执行
  13. flux_屏幕色温调控
  14. RK3399平台开发系列讲解(电源管理篇)11.10、PMIC(生产者)驱动数据结构体
  15. 服务器系统部署方案,系统部署方案.doc
  16. 搅拌摩擦焊有限元仿真分析学习笔记
  17. python字符串赋值多个变量(Python字符串赋值)
  18. 《肖申克的救赎》观后
  19. python各种编辑器、APP、软件下载
  20. CSDN便捷编辑收藏内容和删除收藏夹(网页版)

热门文章

  1. android 音乐播放器----歌词在线下载
  2. 《Linux命令行与shell脚本编程大全》读书笔记————第一章 初识Linux shell
  3. 学霸机器人“拼”高考 将成国内人工智能里程碑
  4. linux C/C++内存检测
  5. [转-SSRF]什么是SSRF
  6. 每天一个linux命令(28):diff 命令
  7. Careercup | Chapter 3
  8. WINDOW7下 配置APACHE+PHP 无法加载MYSQL 的问题
  9. 缺少ntstrsafe.lib kndis5mp.lib解决办法
  10. 关于原型污染漏洞的完整指南