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 jis at most k.
注:特殊情况k=0时直接返回false
bool containsNearbyDuplicate(int* nums, int numsSize, int k) {
if (k == 0)
return false;
for(int i = 0; i < numsSize - 1; i++) {
for(int j = i + 1; j <= i + k && j < numsSize; j++) {
if (nums[i] == nums[j])
return true;
}
}
return false;
}