Java || very easy || Explanation || Hashmap
Intuition\nVery easy approach to solve the problem with the help of single loop and hashmap\n\n# Approach\n\n initiate a Map \n enter all elements and its frequ
# Intuition\nVery easy approach to solve the problem with the help of single loop and hashmap\n\n# Approach\n\n* initiate a Map \n* enter all elements and its frequency\n* inside of entry loop of map ,check\n1. if k==0 , it means any element which is occuring more then twice will always have diff ==0 , ex- 1-1=0 , 15-15 =0 ...\n2. else if map contains element + k , then pair++  \n\n# Complexity\n- Time complexity:\no(n)\n- Space complexity:\no(n)\n\n# Code\n```\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        int n =nums.length;\n      HashMap<Integer,Integer> map = new HashMap<>();\n      for(int i =0;i<n;i++){\n          if(map.containsKey(nums[i]))\n          map.put(nums[i],map.get(nums[i])+1);\n          else\n          map.put(nums[i],1);\n      }\n        int count =0;\n\n      for(Map.Entry<Integer,Integer> entry : map.entrySet()){\n        int val = entry.getValue();\n        int key = entry.getKey();\n\n        if(k==0){\n          if(val>=2)\n            count++;\n        }\n\n        else if(map.containsKey(key+k))\n        count++;\n      }  \n        return count;\n    }\n}\n
['Java']