We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c28406f commit 2313e0fCopy full SHA for 2313e0f
Contains Duplicate II.js
@@ -0,0 +1,19 @@
1
+/*Given an array of integers and an integer k, find out whether there are two distinct indices i and j
2
+in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.*/
3
+
4
+/**
5
+ * @param {number[]} nums
6
+ * @param {number} k
7
+ * @return {boolean}
8
+ */
9
+var containsNearbyDuplicate = function(nums, k) {
10
+ dict = {}
11
+ for(i=0; i<nums.length; i++){
12
+ if(nums[i] in dict){
13
+ if(i-dict[nums[i]]<=k)
14
+ return true
15
+ }
16
+ dict[nums[i]] = i
17
18
+ return false
19
+};
0 commit comments