赞
踩
public static int Search(int[] nums,int target){
int start=0;
int end=nums.length-1;
while(true){
int midle=(start+end)/2;
int midVal=nums[midle];
if(target==midVal){
return midle;
}else {
if(target>midVal){
start=midle+1;
}else{
end=midle-1;
}
}
if(start>end){
return -1;
}
}
}
public static void main(String[] args) {
int[] nums={1,2,3,4,5,6,7,8};
int t=Search(nums,5);
System.out.print(t);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。