JavaScript solution


  • 0
    L
    function containsNearbyDuplicate(nums, k) {
      var map = {};
      for (var i = 0; i < nums.length; i++) {
        if (map[nums[i]] >= 0 && i - map[nums[i]] <= k) return true;
        map[nums[i]] = i;
      }
      return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.