This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Description
Description of the Problem
Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.
A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:
- 0 <= i, j < nums.length
- i != j
- a <= b
- b - a == k
Code
from collections import Counter
class Solution:
def findPairs(self, nums: List[int], k: int) -> int:
ans = 0
c = Counter(nums)
if k == 0:
for val in c.values():
if val > 1:
ans += 1
return ans
for i in c.keys():
if i + k in c.keys():
ans += 1
return ans
Link To The LeetCode Problem
LeetCode