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 absolute difference between i and j is at most k.
public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { if(nums.length <1) return false; if(k <1) return false; int i = 0; int j = k < nums.length ? k :nums.length -1; while(i This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:"LeetCode – 219. Contains Duplicate II"