public class Rectangle {
public static void main(String[]args){
int[] arr={13,15,16,17,19};
int ss=chazhao(15,arr);
System.out.println(ss);
}
public static int chazhao(int key,int[]arr){
int min=0;
int max=arr.length-1;
while(min<=max){
int mid=(min+max)>>1;
if(arr[mid]>key){
max=mid-1;
}else if(arr[mid]<key){
min=mid+1;
}else{
return mid;
}
}
return -1;
}
} |
|