## Bernini @ buffalo

ME转CS,蛋疼菊紧中.........

# leecode_220 Contains Duplicate III

Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k.

class Solution {
public:
bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {
int len=nums.size();
if (len<=1 || k==0 )
return false;

multiset<int> tree;

for (int i=0;i<nums.size();i++){
if (tree.size()>k)
tree.erase(nums[i-k-1]);
if (tree.size()>0){
multiset<int>::iterator low_bound=tree.lower_bound(nums[i]-abs(t));//返回>=nums[i]-abs(t)的第一个值；
multiset<int>::iterator up_bound=tree.lower_bound(nums[i]);//返回>nums[i]的第一个值；

if (low_bound!=tree.end() && abs(*low_bound-nums[i])<=t)
return true;
if (up_bound!=tree.end() && abs(*up_bound-nums[i])<=t)
return true;
}
tree.insert(nums[i]);
}

return false;

}
};

#### [leetcode] 220. Contains Duplicate III 解题报告

2016-01-30 11:09:05

#### leetcode笔记：Contains Duplicate III

2016-02-26 15:43:16

#### leetcode 220: Contains Duplicate III

2015-06-02 08:31:05

#### Leetcode 220 Contains Duplicate III

2015-06-24 19:38:02

#### Leetcode 220. Contains Duplicate III

2017-02-10 14:08:46

#### Leetcode 217. Contains Duplicate & 219. Contains Duplicate II & 220. Contains Duplicate III

2016-05-31 01:05:38

#### LeetCode 220. Contains Duplicate III

2016-06-24 11:21:59

#### Java TreeSet的使用 (LeetCode Contains Duplicate III )

2015-06-03 09:50:18

#### [C语言][LeetCode][219]Contains Duplicate II

2015-08-28 22:45:07

#### leetcode 217. Contains Duplicate（C语言，堆排序，查重）23

2017-10-05 15:23:52