def containsNearbyDuplicate(self, nums, k):
        lookup = {}
        for i, num in enumerate(nums):
            if num not in lookup:
                lookup[num] = i
            else:
                # It the value occurs before, check the difference.
                if i - lookup[num] <= k:
                    return True
                # Update the index of the value.
                lookup[num] = i
        return False
dataset/ETHPy150Open kamyu104/LeetCode/Python/contains-duplicate-ii.py/Solution.containsNearbyDuplicate/original