JAVA 二分法
程序员文章站
2024-03-16 08:39:16
...
public boolean c(){
int[] b={1,4,5,3,6};
Arrays.sort(b);
int target=3;
boolean result=false;
int min=0;
int max=b.length-1;
while(min<=max){
int num = (min+max)/2;
if(target>b[num]){
min=num+1;
}
if(target<b[num]){
max=num-1;
}
if(target==b[num]){
return true;
}
}
return result;
}