• + 0 comments
    Set<Integer> socks = new HashSet<>();
        int result = 0;
        for(int val : ar) {
            if(socks.remove(val)){
                result++;
            } else {
                socks.add(val);
            }
        }
        return result;
    

    This is basically the same but a bit simpler as remove would dothe "contains" part as well.