class Solution(object):

def findPairs(self, nums, k):

"""

:type nums: List[int]

:type k: int

:rtype: int

"""

idic=collections.defaultdict(list)

c=0

cont=collections.Counter(nums)

if k==0:

return len([1 for q in cont if cont[q]>=2])

if k<0:

return 0

for i in list(set(nums)):

if i in idic:

c+=len(idic[i])

idic[i-k].append(i)

idic[i+k].append(i)

return c