fork download
  1. class Solution {
  2. public int countKDifference(int[] nums, int k) {
  3. int n=nums.length;
  4. HashMap<Integer,Integer>f = new HashMap<>();
  5. int count=0;
  6.  
  7. f.put(nums[0],1);
  8. for(int j=1;j<n;j++){
  9. if(f.containsKey(nums[j]-k)){
  10. count+=f.get(nums[j]-k);
  11. }
  12. if(f.containsKey(nums[j]+k)){
  13. count+=f.get(nums[j]+k);
  14. }
  15.  
  16. f.put(nums[j],f.getOrDefault(nums[j],0)+1);
  17. }
  18. return count;
  19.  
  20. }
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: cannot find symbol
        HashMap<Integer,Integer>f = new HashMap<>();
        ^
  symbol:   class HashMap
  location: class Solution
Main.java:4: error: cannot find symbol
        HashMap<Integer,Integer>f = new HashMap<>();
                                        ^
  symbol:   class HashMap
  location: class Solution
2 errors
stdout
Standard output is empty