Java Soln | 1 pass | O(N)- time and space
\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        HashSet<Integer> set = new HashSet<>();\n\t\tint count = 0;\n\t\t\n\t\tHashSet<Intege
```\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        HashSet<Integer> set = new HashSet<>();\n\t\tint count = 0;\n\t\t\n\t\tHashSet<Integer> duplicateset = new HashSet<>();\n\t\t\n\t\t\n\t\tfor (int n : nums) {\n\t\t\tif (set.contains(n)) {\n\t\t\t\tif(k==0 && !duplicateset.contains(n)) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tduplicateset.add(n);\n\t\t\t\t}\n\t\t\t}else {\n\t\t\t\t//check diff of that number exist to find pair. \n\t\t\t\t// It will not count (a,b) and (b,a) as 1 set of number is not added to set yet.\n\t\t\t\tif(k!=0 && set.contains(n-k)) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tif(k!=0 && set.contains(n+k)) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tset.add(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn count;\n    }\n}\n```
[]