mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-08-06 01:20:05 +08:00
794 B
794 B
题目地址
思路
C++代码
class Solution {
public:
bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {
multiset<int> s;
if(nums.empty() || k==0) return false;
for(int i=0;i<nums.size();i++){
if(s.size()>k){
s.erase(nums[i-k-1]);
}
auto index = s.lower_bound(nums[i]-t);
if(index!=s.end() && abs(*index-nums[i])<=t) return true;
s.insert(nums[i]);
}
return false;
}
};
更过算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。