标签:lan util ddl 二分 eth oid middle string rate
import java.util.Random;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a={1,4,5,7,7,7,7,8,9,12,43,65};
int ercha = erfen(77, a);
System.out.println(ercha);
}
public static int erfen(int k,int[] a) {
int left = 0;
int right=a.length-1;
int middle=0;
if(k<a[left]||k>a[right]||left>right){
return -1;
}
while (left<=right) {
middle=(left+right)/2;
if (a[middle]==k) {
return a[middle];
}else if (a[middle]>k) {
right=middle-1;
}else if (a[middle]<k) {
left=middle+1;
}
}
return -1;
}
}
标签:lan util ddl 二分 eth oid middle string rate
原文地址:https://www.cnblogs.com/dutf/p/14090592.html