打印数组中的重复元素

package com.NodePair;
public class BitSet {
int[] bitset;
public BitSet(int size)
{
bitset=new int[size>>5];
}
void set(int pos)
{
int arraynumber=pos>>5;
int bitnumber=pos&0x1f;
bitset[arraynumber]|=1< }


boolean get(int pos)
{
int arraynumber=pos>>5;
int bitnumber=pos&0x1f;
return (bitset[arraynumber]&(1< }

}


public class CheckDuplicates {
public void checkduplicate(int[] array)
{
BitSet bitset=new BitSet(32000);
for(int i=0;i {
int num=array[i];
int val=num-1;
if(bitset.get(val))
System.out.println(num);
else bitset.set(val);
}
}
}

你可能感兴趣的:(cracking,the,coding,interview)