Java O(n) Hashmap One Pass Easy Solution!!
\npublic int findPairs(int[] nums, int k) {\n        int count =0;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        \n        for(int i = 0; i
```\npublic int findPairs(int[] nums, int k) {\n        int count =0;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        \n        for(int i = 0; i < nums.length; i++) {\n            if(!map.containsKey(nums[i])) {\n                if(map.containsKey(nums[i] + k)) count++;\n                if(map.containsKey(nums[i] - k)) count++;\n                map.put(nums[i], 1);\n            } else if (k == 0) {\n                   if(map.get(nums[i]) == 1)\n                      count++;\n                   map.put(nums[i], map.get(nums[i]) + 1);\n            }         \n        }\n        return count;\n    }\n```
['Java']