• + 0 comments

    **The Best Solution Without Object OverHead from Hash DS. **

    import java.util.Scanner;

    public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt();

        BitSet bset = new BitSet(100);
        int count = 0;
    
        for(int i = 0; i < n; i++) {
            int num = scan.nextInt();
            //if toggled on
            if(bset.get(num)) {
                count++;
                bset.clear(num);
            }else {
                bset.set(num);
            }
        }
    
        System.out.println(count);
        scan.close();
    }
    

    }

    class BitSet{ private long[] bits; private int size;

    public BitSet(int size) {
        this.size = size;
        this.bits = new long[(size + 64) / 64];
    }
    
    public BitSet() {
        this(64);
    }
    
    public void set(int index) {
        if(index < 0) {
            throw new IndexOutOfBoundsException("index must be > 0");
        }else if(index > size) {
            resize(index);
        }
    
        bits[index / 64] |= (1L << (index % 64));
    }
    
    public boolean get(int index) {
        if(index < 0 || index > size) {
            throw new IndexOutOfBoundsException("Index must be > 0 & < size");
        }
    
        return (bits[index / 64] & (1L << (index % 64))) != 0;
    }
    
    public void clear(int index) {
        if(index < 0 || index > size) {
            throw new IndexOutOfBoundsException("Index must be > 0 & < size");
        }
    
        bits[index / 64] &= ~(1L << (index % 64));
    }
    
    public int size() {
        return size;
    }
    
    private void resize(int index) {
        long[] newBits = new long[(index + 64) / 64];
        System.arraycopy(bits, 0, newBits, 0, bits.length);
        bits = newBits;
        size = index;
    }
    

    }