Contains Duplicate II

给一个数组和一个数字k, 问数组有没有两个数想问, 但是index的差为最多k.

public class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();

    for(int i = 0; i <  nums.length; i++) {
        Integer ord = map.put(nums[i], i);
        if(ord != null && i - ord <= k) {
            return true;
        }
    }

    return false;
}
}