pascals-triangle-ii leetcode C++
Given an index k, return the k th row of the Pascal's triangle.
For example, given k = 3, Return[1,3,3,1].
Note: Could you optimize your algorithm to use only O(k) extra space?
C++
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> dp;
dp.push_back(1);
for(int i = 1; i <= rowIndex;i++){
vector<int> tmp;
tmp.push_back(1);
for(int j = 1; j < i; j++)
tmp.push_back(dp[j]+ dp[j-1]);
tmp.push_back(1);
dp = tmp;
}
return dp;
}
};
pascals-triangle-ii leetcode C++的更多相关文章
- [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, ...
- Pascal's Triangle II —LeetCode
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Pascal's Triangle II leetcode
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Pascal's Triangle II Leetcode java
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...
- 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题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- ...
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- LeetCode OJ 119. 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, ...
- LeetCode: Pascal's Triangle II 解题报告
Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...
随机推荐
- liunx常见指令
linux目录结构 bin:存储普通命令 sbin:存储超级命令 home:存储普通用户 root:存储超级用户 usr /usr/local:下存储数据或软件,通常软件都放在其中 tmp:临时目录 ...
- TypeScript与面向对象
目录 1.引 2.类(class) 3.构造函数和this 4.继承 5.super 6.抽象类 7.接口 8.属性的封装 9.泛型 1.引 简而言之就是程序之中所有的操作都需要通过对象来完成.一切操 ...
- 学习PHP中的信息格式化操作
在国际化组件的学习过程中,我们已经接触过了 NumberFormatter 这种数字的格式化操作,它可以让我们将数字转换成标准格式.货币.本地语言等形式.今天我们来学习的是另一种专门用于信息格式化的类 ...
- Nginx系列(6)- nginx: [error] CreateFile() "D:\nginx-1.20.1/logs/nginx.pid" failed (2: The system cannot find the file specified)
背景 修改nginx配置文件nginx.conf后,想要重启nginx使配置生效.cmd进入nginx安装目录,输入命令: nginx -s reload 报错:nginx: [error] Crea ...
- java 工具类 验证码
第一步: 引入工具类 工具类一: import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import jav ...
- Loj#3026-「ROIR 2018 Day1」管道监控【Trie,费用流】
正题 题目链接:https://loj.ac/p/3026 题目大意 给出\(n\)个点的一棵外向树,然后\(m\)个字符串和费用表示你每次可以花费这个费用覆盖路径字符串和给出字符串相等的路径,求覆盖 ...
- P2179-[NOI2012]骑行川藏【导数,二分】
正题 题目链接:https://www.luogu.com.cn/problem/P2179 题目大意 给出\(E\)和\(n\)个\(s_i,k_i,u_i\)求一个序列\(v_i\)满足 \[\s ...
- 学会了这些英文单词,妈妈再也不用担心我学不会Python
前言 很多转行或刚入行做测试的小伙伴学习Python时,经常会问一句话:我英语不好能不能学会代码. 答案是:肯定的!你如果英语好学开发语言肯定要比不会英语的小伙伴学起来.当代码报错时全是英文,毕竟 ...
- SQL Server附加数据库错误5120处理方法
SQL Server附加数据库5120错误 当我们从另外一台服务器复制过来的数据库,可能会有如下错误: 解决方法 1.给数据库所在文件夹增加用户Everyone并赋予完全控制权限 2.以管理员身份运行 ...
- Jetpack Compose学习(6)——关于Modifier的妙用
原文: Jetpack Compose学习(6)--关于Modifier的妙用 | Stars-One的杂货小窝 之前学习记录中也是陆陆续续地将常用的Modifier的方法穿插进去了,本期就来详细的讲 ...