image_2021-10-15_03-57-31.png
33 KB
#N2006 Count Number of Pairs With Absolute Difference K
problem link=>https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k/
#solution
problem link=>https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k/
#solution
class Solution {
public int countKDifference(int[] nums, int k) {
int count=0;
int[] helper=new int[101];
for (int n:nums)
helper[n]++;
for (int i=k+1; i<101; i++)
count+=helper[i]*helper[i-k];
return count;
}
}