Counting Numbers Day 7 Leetcode Challenge Java Solution 0ms.
class Solution {
    public int countElements(int[] arr) {
        int count=0;
        HashSet<Integer> hs = new HashSet<>();
        for(int num : arr){
            hs.add(num);
        }
        
        for(int num : arr){
            if(hs.contains(num+1)){
                count++;
            }
        }
        return count;
    }
}
Comments (0)