public class Solution {
public bool ContainsNearbyDuplicate(int[] nums, int k) {
Dictionary<int, int> dict = new Dictionary<int, int>();
for (int i = 0; i < nums.Length; i++) {
int index;
if (dict.TryGetValue(nums[i], out index)) {
if (i - index <= k) {
return true;
}
}
dict[nums[i]] = i;
}
return false;
}
}
219. 数组重复元素2 Contains Duplicate II
原文:http://www.cnblogs.com/xiejunzhao/p/9c2a98f21d2e33e6a295a9cf45a58da1.html