###### 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 boolean containsNearbyDuplicate(int[] nums, int k) {
if(nums == null || nums.length < 2)   return false;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i = 0; i < nums.length; i++) {
if(map.containsKey(nums[i]) && i - map.get(nums[i]) <= k) {
return true;
}
map.put(nums[i], i);
}
return false;
}
}

#### leetcode 219: Contains Duplicate II

2015-05-29 15:02:09

#### 【LeetCode-面试算法经典-Java实现】【219-Contains Duplicate II（包含重复元素II）】

2015-08-29 06:36:21

#### leetcode_c++：Contains Duplicate II(219)

2016-06-18 13:33:40

#### 219. Contains Duplicate II [easy] (Python)

2016-06-14 19:59:14

#### leetcode笔记：Contains Duplicate II

2016-02-24 18:31:03

#### LeetCode 219. Contains Duplicate II（C++版）

2017-03-31 13:39:15

#### LeetCode 219:Contains Duplicate II

2015-05-31 18:41:22

#### [leetcode-219]Contains Duplicate II（Ｃ）

2015-08-26 11:03:54

#### leetcode 219 Contains Duplicate II C++

2016-06-05 15:09:27

#### Leetcode—Contains Duplicate II—Python

2015-06-17 20:07:53

## 不良信息举报

LeetCode:Contains Duplicate II