446 Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
详见:https://leetcode.com/problems/arithmetic-slices-ii-subsequence/description/
C++:
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& A)
{
int res = 0, n = A.size();
vector<unordered_map<int, int>> dp(n);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < i; ++j)
{
long delta = (long)A[i] - A[j];
if (delta > INT_MAX || delta < INT_MIN)
{
continue;
}
int diff = (int)delta;
++dp[i][diff];
if (dp[j].count(diff))
{
res += dp[j][diff];
dp[i][diff] += dp[j][diff];
}
}
}
return res;
}
};
参考:https://www.cnblogs.com/grandyang/p/6057934.html
446 Arithmetic Slices II - Subsequence 算数切片之二 - 子序列的更多相关文章
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- LeetCode 446. Arithmetic Slices II - Subsequence
原题链接在这里:https://leetcode.com/problems/arithmetic-slices-ii-subsequence/ 题目: A sequence of numbers is ...
- 446. Arithmetic Slices II - Subsequence
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- 第六周 Leetcode 446. Arithmetic Slices II - Subsequence (HARD)
Leetcode443 题意:给一个长度1000内的整数数列,求有多少个等差的子数列. 如 [2,4,6,8,10]有7个等差子数列. 想了一个O(n^2logn)的DP算法 DP[i][j]为 对于 ...
- Arithmetic Slices II - Subsequence LT446
446. Arithmetic Slices II - Subsequence Hard A sequence of numbers is called arithmetic if it consis ...
- Leetcode: Arithmetic Slices II - Subsequence
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [Swift]LeetCode446. 等差数列划分 II - 子序列 | Arithmetic Slices II - Subsequence
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- LeetCode446. Arithmetic Slices II - Subsequence
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [LeetCode] Arithmetic Slices 算数切片
A sequence of number is called arithmetic if it consists of at least three elements and if the diffe ...
随机推荐
- Nuget公布Dll
今天要開始写ViewModel了,写完之后系统里的ViewModel都汇总到我这里.然后由我负责ViewModel的公布跟维护,所以Nuget公布Dll就要熟练啦~ 一,安装工具 1.Nuget Pa ...
- 怎样更好的设计你的REST API之基于REST架构的Web Service设计及REST框架实现
一.REST 含状态传输(英文:Representational State Transfer,简称REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格. 眼下在 ...
- 命题作文:在一棵IPv4地址树中彻底理解IP路由表的各种查找过程
这是一篇命题作文.近期一直想写点东西,但一直找不到题目.正好收到一封邮件,有人问我Linux路由表的布局问题以及路由缓存的问题,加之前些日子又帮人做了一个片上路由表,所以认为这是个好题目,索性花了多半 ...
- 优化tomcat配置(从内存、并发、缓存)优化
一.Tomcat内存优化 ** Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 catalina.sh 中设置 java_OPTS 参数. JAVA_O ...
- 程序员的vim
1,所有的Unix like系统都会内建vi文书编辑器,其他的文书编辑器则不一定会存在,但是目前我们使用比较多的是vim编辑器 vim具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序 ...
- sublime text3使用插件SublimeTextTrans设置透明度
推荐一款在windows上设置sublime2和sublime3背景透明度的插件:SublimeTextTrans, 下载地址:https://github.com/vhanla/SublimeTex ...
- YTU 1001: A+B Problem
1001: A+B Problem 时间限制: 1 Sec 内存限制: 10 MB 提交: 4864 解决: 3132 [提交][状态][讨论版] 题目描述 Calculate a+b 输入 Tw ...
- YTU 2402: Common Subsequence
2402: Common Subsequence 时间限制: 1 Sec 内存限制: 32 MB 提交: 63 解决: 33 题目描述 A subsequence of a given seque ...
- YTU 2887: D--机器人Bill
2887: D--机器人Bill 时间限制: 1 Sec 内存限制: 128 MB 提交: 112 解决: 22 题目描述 最近,Dr. Jiang 新设计一个机器人Bill.Bill很聪明,会做 ...
- bootstrap3.0学习笔记记录1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...