/*
* @lc app=leetcode.cn id=219 lang=javascript
*
* [219] 存在重复元素 II
*/
// @lc code=start
/**
* @param {number[]} nums
* @param {number} k
* @return {boolean}
*/
var containsNearbyDuplicate = function (nums, k) {
let map = new Map()
for (let i = 0; i < nums.length; i++) {
if (map.has(nums[i]) && i - map.get(nums[i]) <= k) {
return true
} else {
//更新最近的i值
map.set(nums[i], i)
}
}
return false
}
// @lc code=end