Leetcode 119 Pascal's Triangle II 数论递推
杨辉三角,这次要输出第rowIndex行
用滚动数组t进行递推
t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1];
class Solution {
public:
vector<int> getRow(int rowIndex) {
if(rowIndex < ) return vector<int>(rowIndex + ,);
int n = rowIndex;
vector<int> t[];
for(int i = ; i < ; ++i){
t[i].resize(n + , );
}
for(int i = ; i <= n; ++i){
for(int j = ; j < i; ++j){
t[(i+)%][j] = t[i%][j] + t[i%][j - ];
}
}
return t[(n+) % ];
}
};
Leetcode 119 Pascal's Triangle II 数论递推的更多相关文章
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- LeetCode 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 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- leetcode 119 Pascal's Triangle II ----- java
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Java [Leetcode 119]Pascal's Triangle II
题目描述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
- C#解leetcode:119. Pascal's Triangle II
题目是: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
- Java for LeetCode 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 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle
118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...
随机推荐
- CentOS7安装mysql5.7.11
开始安装 yum update yum install wget wget http://repo.mysql.com/mysql57-community-release-el7-7.noarch.r ...
- workerman 的属性
<?php /** * Created by PhpStorm. * User: zeopean * Date: 2016-08-26 * Time: 16:35 */ use Workerma ...
- 如何编译Less
什么是LESS LESSCSS是一种动态样式语言,属于CSS预处理语言的一种.它编译后就是CSS了,大名鼎鼎的前端框架BootStrap就是用这个语言写的 下面示范下怎么用LESS编译成CSS,尽量简 ...
- freemarker 数字格式化函数
${num?string('0.00')} 如果小数点后不足两位,用 0 代替 ${num?string('#.##')} 如果小数点后多余两位,就只保留两位,否则输出实际值 输出为:1239765. ...
- shell 小问题汇总
写脚本的时候难免会判断变量是否为空或者为定义 变量a未定义 if [ -n $a ];then echo "exists"; else echo "not exists& ...
- Jquery点击发送按钮后,按钮文本倒计时
1.html代码 <input type="number" id="mobileNo" placeholder="请输入手机号" /& ...
- ios 上架需要注意的问题
前段时间上架产品的时候,因为定位提示问题被拒绝了,而且集成了融云及时聊天的key,没有从测试环境升级到生产环境,所以记录一下APP上架所需要注意的事项. 1.程序没有崩溃性BUG 2.程序不存在逻辑性 ...
- 理解em,rem以及rem的失效问题
在平常做网站写代码的时候一般都是使用px,在之前的学习时就略微的学习了一些关于em.rem的知识,但是由于一直没有用到过,所以几乎全部忘记了.今天在研究一些知识的时候用到了em,所以特意将学到的知识总 ...
- asp.net简单小爬虫
所谓爬虫简单点说,就是把别人网站上的东西爬下来,至于爬做什么用就看你自己了,比如:把别人网站上的东西爬下来放在自己网站中(感觉有点像小偷^v^). 这里随便写了一个爬虫代码(可以自己再去进行完善): ...
- MySQL关键性能监控(QPS/TPS)
原文链接:http://www.cnblogs.com/chenty/p/5191777.html 工作中尝尝会遇到各种数据库性能调优,除了查看某条SQL执行时间长短外,还需要对系统的整体处理能力有更 ...