java 二分法查找最接近的一个数字

public static Integer getNumberThree(Integer[] intarray,Integer number){
int index = Math.abs(number-intarray[0]);
int result = intarray[0];
for (int i : intarray) {
int abs = Math.abs(number-i);
if(abs <= index){
index = abs;
result = i;
}
}
return result;
}

猜你喜欢

转载自www.cnblogs.com/austinspark-jessylu/p/11271525.html