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] ]

C++

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

pascals-triangle leetcode C++的更多相关文章

  1. [Leetcode] pascals triangle ii 帕斯卡三角

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

  2. [LeetCode][Java]Triangle@LeetCode

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

  3. Triangle leetcode

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

  4. Triangle——LeetCode

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

  5. Pascal's Triangle leetcode

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

  6. Triangle LeetCode |My solution

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

  7. Pascal's Triangle leetcode java(杨辉三角)

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

  8. Triangle leetcode java

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

  9. triangle leetcode C++

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

  10. 决战Leetcode: easy part(1-50)

    本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! em ...

随机推荐

  1. vue-cli3项目中使用vue-ueditor-wrap

    Vue + UEditor + v-model 双向绑定 一.安装 1 npm i vue-ueditor-wrap 2 # 或者 3 yarn add vue-ueditor-wrap 二.下载文件 ...

  2. Jmeter扩展组件开发(6) - 将响应结果数据显示到查看结果树中

    CODE //用来存储响应数据,目的是将响应结果放到查看结果树当中private String resultData;/** 这个方法就是实现你具体功能逻辑的方法* @param javaSample ...

  3. 如何实现Orchard Core CMS的全文索引

    Orchard Core提供了Lucene功能,允许您在网站上进行全文搜索.大多数情况下,在运行博客或简单的代理网站时,您可能需要在页面内容中进行搜索.在Orchard Core中,您可以使用Liqu ...

  4. httprunner版本没有更新问题

    使用命令行创建虚拟环境,创建脚手架目录后,使用pycharm打开所创建的脚手架目录. 执行:hrun demo_testcase_request.yml 提示: E:\hrun_ven\test_hr ...

  5. 使用python3中的2to3.py执行数据迁移

    1.在python默认安装的位置找到Tools\scripts 2.找到2to3.py 3.在所在文件夹shift+右键打开终端 4.执行命令python 2to3.py -w 需要做数据迁移的数据路 ...

  6. 鸿蒙内核源码分析(ELF解析篇) | 你要忘了她姐俩你就不是银 | 百篇博客分析OpenHarmony源码 | v53.02

    百篇博客系列篇.本篇为: v53.xx 鸿蒙内核源码分析(ELF解析篇) | 你要忘了她姐俩你就不是银 | 51.c.h.o 加载运行相关篇为: v51.xx 鸿蒙内核源码分析(ELF格式篇) | 应 ...

  7. 如何通过云效Flow完成自动化部署—主机部署

    如何通过云效Flow完成自动化部署-主机部署,云效流水线Flow是持续交付的载体,通过构建自动化.集成自动化.验证自动化.部署自动化,完成从开发到上线过程的持续交付.通过持续向团队提供及时反馈,让交付 ...

  8. 在modal中的datetimepicker插件BUG修复

    前言:因为在模态框用到datetimepicker这一日期控件,而选中日期时,会触发模态框的再次打开,导致上面表单选的值会重新加载 解决办法: 用stopPropagation() 方法阻止事件传播, ...

  9. 4 个场景揭秘,如何低成本让容器化应用 Serverless 化?

    作者 | changshuai FaaS 的门槛 Serverless 形态的云服务帮助开发者承担了大量复杂的扩缩容.运维.容量规划.云产品打通集成等责任,使得开发者可以专注业务逻辑.提高交付速度 ( ...

  10. sql提示1055 不让你group by

    是不是突然写好的sql语句 部署上去就 Expression #2 of SELECT list is not in GROUP BY clause and containsnonaggregated ...