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 ...
随机推荐
- C语言最小生成树prim算法(USACO3.1)
/* ID: hk945801 LANG: C++ TASK: agrinet */ #include<iostream> #include<cstdio> using nam ...
- 【Mongodb教程 第七课 】MongoDB 查询文档
find() 方法 要从MongoDB 查询集合数据,需要使用MongoDB 的 find() 方法. 语法 基本的find()方法语法如下 >db.COLLECTION_NAME.find() ...
- SpringMVC+MyBatis+JMS+JTA(分布式事务)
SpringMVC+MyBatis 相信已经是如今企业开发中经常使用技术了. 由于一些需求,我们须要集成JMS(我使用的是ActiveMQ).大家应该都知道.MQ也能够觉得是一个数据源.数据也是数据源 ...
- win系统下启动linux上的kafka集群及使用
一.首先在win系统下C:\Windows\System32\drivers\etc文件夹中hosts文件加入例如以下内容: 10.61.6.167 slaves1 10.61.6.168 slave ...
- Receiver type ‘X’ for instance message is a forward declaration
这往往是引用的问题. ARC要求完整的前向引用,也就是说在MRC时代可能仅仅须要在.h中申明@class就能够,可是在ARC中假设调用某个子类中未覆盖的父类中的方法的话.必须对父类.h引用,否则无法编 ...
- Android 网络调试 adb tcpip 开启方法
查看ip地址:adb shell ifconfig 1.连接USB数据线,打开usb调试,使用windows的“运行”命令行方式:(此方法需配置adb环境变量,也可直接进入adb工具目录执行\andr ...
- python dig trace 功能实现——通过Querying name server IP来判定是否为dns tunnel
dns tunnel确认方法,查询子域名最终的解析地址: 使用方法:python dig_trace.py "<7cf1e56b 67fc90f8 caaae86e 0787e907 ...
- Burnside&Polya
以前只是直接用了这两个式子..今天才仔细看了证明..[网上的真是难懂啊 我看的几个博客地址(各有优缺): 其实如果能懂的话 只看博客B就可以了 首先是一些置换群方面的定义和性质 博客A:http:/ ...
- DOS命令汇总
汇总如下: Dos基础命令梳理思路 小编初来乍道, 不清楚我的插图在我发布后会不会不清晰, 因为我在排版时看到插入的图片是清晰的, 以前见其他条友发布的文章中总有不晰的图片, 很是不爽. 所以如果有不 ...
- zoj 3865
Superbot Time Limit: 2 Seconds Memory Limit: 65536 KB Superbot is an interesting game which you ...