Leetcode-5214 Longest Arithmetic Subsequence of Given Difference(最长定差子序列)

Posted asurudo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-5214 Longest Arithmetic Subsequence of Given Difference(最长定差子序列)相关的知识,希望对你有一定的参考价值。

 1 typedef long long ll;
 2 typedef pair<int,int> P;
 3 #define _for(i,a,b) for(register int i = (a);i < b;i ++)
 4 #define _rep(i,a,b) for(register int i = (a);i > b;i --)
 5 #define INF 0x3f3f3f3f
 6 #define MOD 100000000
 7 #define maxn 10003
 8 
 9 
10 class Solution
11 
12     map<int,int> m;
13     public:
14         int longestSubsequence(vector<int>& arr, int difference)
15         
16             int ans = 1;
17             _for(i,0,arr.size())
18             
19                 auto iter = m.find(arr[i]-difference);
20                 if(iter==m.end())
21                     m[arr[i]] = 1;
22                 else
23                 
24                     int k = iter->second;
25                     m[arr[i]] = k+1;
26                     ans = max(ans,k+1);
27                 
28             
29             return ans;
30         
31 ;

 

以上是关于Leetcode-5214 Longest Arithmetic Subsequence of Given Difference(最长定差子序列)的主要内容,如果未能解决你的问题,请参考以下文章

php ARI INT

ARI JS 客户端静音错误

每日一讲 | 新型ARi改变nmCRPC治疗格局——谢立平教授

聚类模型评价(python) AMI ARI FMI

Scikit-learn:用于集群评估的 ARI 分数

PCIe ARI (Alternative Routing-ID Interpretation)介绍