Java | Hashmap
\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        HashMap<Integer,Integer> map=new HashMap<>();\n        int c=0;\n        for(int val:
```\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        HashMap<Integer,Integer> map=new HashMap<>();\n        int c=0;\n        for(int val:nums )\n            {\n                map.put(val,map.getOrDefault(val,0)+1);\n            \n            }\n        for(int i:map.keySet())\n            {\n                if((k==0 && map.get(i)>1)||(k>0 && map.containsKey(i+k)))\n                    c++;\n            }\n        return c;\n    }\n}\n```
['Java']