1 Star 1 Fork 0

laodasbch/Leetcode-Complete-Guide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
446.txt 780 Bytes
一键复制 编辑 原始数据 按行查看 历史
JunB(66哥) 提交于 2020-10-23 01:53 +08:00 . Create 446.txt
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& A) {
long res=0;
int N=A.size();
vector<unordered_map<long,long>>dp(N);
for(int i=0;i<A.size();i++){
unordered_map<long,long>&cur=dp[i];
for(int j=i-1;j>=0;j--){
long a=A[i];long b=A[j];
long dif=a-b;
if(cur.count(dif)==0){
cur[dif]=0;
}
unordered_map<long,long>&hash=dp[j];
if(hash.count(dif)==0){
cur[dif]++;
}else{
res+=hash[dif];
cur[dif]+=hash[dif]+1;
}
}
}
return (int)(res);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/laodasbch/Leetcode-Complete-Guide.git
git@gitee.com:laodasbch/Leetcode-Complete-Guide.git
laodasbch
Leetcode-Complete-Guide
Leetcode-Complete-Guide
master

搜索帮助