给定一个整数数组nums,以及一个整数k,找出其中所有差恰好为k的不重复数对。
class Solution(object):
def findPairs(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
c = collections.Counter(nums)
count = 0
for i in c:
if k > 0 and i + k in c or k == 0 and c[i] > 1:
count += 1
return count