Using HashMap | Java Code with explaination
If you find it useful do upvote\n\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        \n        Map<Integer, Integer> map = new HashMap<>(
If you find it useful do upvote\n```\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        \n        Map<Integer, Integer> map = new HashMap<>();\n        for(int i = 0; i < nums.length; i++){\n            if(map.containsKey(nums[i])){\n                // the array element and  increament the frequence by 1\n                map.put(nums[i], map.get(nums[i]) + 1);\n            } else {\n                // keep the frequene of current element as 1\n                map.put(nums[i], 1);\n            }\n        }\n        int count = 0;\n        //create key set\n        Set<Integer> set = map.keySet();\n        for(int num: set){\n            //first check\n            if(k > 0 &&map.containsKey(num + k)){\n                count++;\n            }\n            // second check\n            if(k==0 && map.get(num) > 1){\n                count++;\n            }\n        }\n        return count;\n    }\n}\n```\n\n```\nTime Complexity : O(N)\nSpace Complexity : O(N)\n```\n\n**NOTES**\n[(https://github.com/rizonkumar/LeetCode-Notes/blob/bb59b2137e810d07dd1f91470e31e4842bf70fa4/532.pdf)]
[]