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.

# -*- coding:utf-8 -*-
class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
        if len(nums) <= 1:
            return False
        dic = {}
        for key, value in enumerate(nums):
            if value in dic and key - dic[value] <= k:
                return True
            dic[value] = key
        return False

Leetcode学习(28)——  Contains Duplicate II_leetcode