# LeetCode -- Contains Duplicate II

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

public class Solution {
public bool ContainsNearbyDuplicate(int[] nums, int k)
{
var hash = new Dictionary<int, int>();
for(var i = 0;i < nums.Length; i++){
if(!hash.ContainsKey(nums[i])){
}
else{
if(Math.Abs(hash[nums[i]] - i) <= k){
return true;
}
else{
hash[nums[i]] = i;
}
}
}

return false;
}
}

• 本文已收录于以下专栏：

## leetcode: (219) Contains Duplicate II

【Question】 Given an array of integers and an integer k, find out whether there are two distinct ind...
• zk031
• 2015-08-28 20:50
• 143

## LeetCode 之 Contains Duplicate I II III — C++ 实现

Contains Duplicate   Given an array of integers, find if the array contains any duplicates. Your fu...

## LeetCode | Contains Duplicate II

Given an array of integers and an integer k, find out whether there there are two distinct indices ...

## 【Leetcode Algorithm】Contains Duplicate II

Given an array of integers and an integer k, find out whether there there are two distinct indices...

## leetcode笔记--Contains Duplicate I & II & III

Contains Duplicate 题目：难度（Easy） Given an array of integers, find if the array contains any duplicat...

## Leetcode 219. Contains Duplicate II

Given an array of integers and an integer k, find out whether there are two distinct indices i and j...

## [leetcode]: 219. Contains Duplicate II

1.题目Given an array of integers and an integer k, find out whether there are two distinct indices i a...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)