# Middle-题目122：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.

public class Solution {
public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
if(k < 1 || t < 0)
return false;
TreeSet<Integer> set = new TreeSet<>();
for(int i = 0; i < nums.length; i++){
int n = nums[i];
if(set.floor(n) != null && n <= t + set.floor(n) ||
set.ceiling(n) != null && set.ceiling(n) <= t + n)
return true;
if (i >= k)
set.remove(nums[i - k]);
}
return false;
}
}

68ms,beats 10.72%,众数23ms,5.88%
Cmershen的碎碎念：

#### Leetcode 220 Contains Duplicate III

2015-06-24 19:38:02

#### leetcode 220: Contains Duplicate III

2015-06-02 08:31:05

#### Leetcode 220. Contains Duplicate III

2017-02-10 14:08:46

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

2016-01-30 11:09:05

#### 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

#### LeetCode 220. Contains Duplicate III（检查重复）

2016-05-06 08:32:53

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

2015-08-28 22:45:07

#### leetcode笔记：Contains Duplicate III

2016-02-26 15:43:16

#### 220. Contains Duplicate III

2016-03-22 10:48:11