class Solution {
public:
bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {
set<long long> pot;
for(int i = 0; i < nums.size(); ++i){
long long val = nums[i];
if(i > k)
pot.erase(nums[i-k-1]);
auto pos = pot.lower_bound(val - t);
if(pos != pot.end() && *pos - val <= t)
return true;
else
pot.insert(val);
}
return false;
}
};
220. Contains Duplicate III
最新推荐文章于 2020-02-09 13:51:31 发布