适用范围:有序且均匀的数组,数组长度必须是大于1 时间复杂度是O(log(2)log(2)N)
找到则输出下标,未找到返回-1
class Solution {
public int search(int[] nums, int target) {
int left = 0;
int right = nums.length-1;
int center;
while(left<=right){
center = left+(target-nums[left])/(nums[right]-nums[left])*(right-left);
if(target == nums[center]){
System.out.println(center);
return center;
}
else if(target < nums[center]){
right = center - 1;
}else if(target > nums[center]){
left = center+1;
}
}
return -1;
}
}