class Solution {
public:
int longestSubsequence(vector<int> &arr, int difference) {
int ans = 0;
unordered_map<int, int> dp;
for (int v: arr) {
dp[v] = dp[v - difference] + 1;
ans = max(ans, dp[v]);
}
return ans;
}
};
最长定差子序列
最新推荐文章于 2024-09-06 10:38:06 发布