public class Test{
public static void main(String[] args){
int[] arr=new int[200000000];
for(int i=0;i<arr.length;i++){
arr[i]=i/2;
}
arr[199999998]=1;
arr[199999999]=100005099; //不重复的数
int min=arr[0];
int max=arr[0];
for(int i=0;i<arr.length;i++){
if(arr[i]<min)
min=arr[i];
if(arr[i]>max)
max=arr[i];
}
byte[] buckets=new byte[(max-min)/4+1];
for(int i=0;i<arr.length;i++){
int num=arr[i];
int j=(num-min)/4;
int k=(num-min)%4;
if(((buckets[j]>>(k*2))&3)<3)
buckets[j]+=(1<<(k*2));
}
for(int i=0;i<buckets.length;i++){
byte b=buckets[i];
int num=i*4+min;
if((b&3)==1) {
num += 0;
System.out.println("num:"+num);
}
if(((b>>2)&3)==1) {
num += 1;
System.out.println("num:"+num);
}
if(((b>>4)&3)==1) {
num += 2;
System.out.println("num:"+num);
}
if(((b>>6)&3)==1) {
num += 3;
System.out.println("num:"+num);
}
}
}
}
输出:
num:100005099