Given an integer array nums and an integer k, return the number of unique pairs of values (a, b) such that a and b both appear in nums and |a - b| = k.
A pair is considered unique based on its values, not on the indices where those values occur in nums.
Note: When
k = 0, a valid pair requires a value to appear at least twice innums.
Constraints:
nums.length
nums[i]
k
Given an integer array nums and an integer k, return the number of unique pairs of values (a, b) such that a and b both appear in nums and |a - b| = k.
A pair is considered unique based on its values, not on the indices where those values occur in nums.
Note: When
k = 0, a valid pair requires a value to appear at least twice innums.
Constraints:
nums.length
nums[i]
k