//在 O(logN) 时间内,从循环有序数组里查找元素
//二分之后,总有一半是有序数组
public static int searchInLoopSortedArray(int[] nums, int target) {
if(nums.length == 0) return -1;
int low = 0;
int high = nums.length - 1;
while (low <= high) {
int mid = low + ((high - low) >> 1);
if(nums[mid] == target) return mid;
if(nums[low] <= nums[mid]) {
if(nums[mid] > target && nums[low] <= target) {
high = mid - 1;
} else {
low = mid + 1;
}
} else if(nums[low] > nums[mid]) {
if(nums[mid] < target && nums[high] >= target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
}
return -1;
}
来源:CSDN
作者:发霉的宅大人
链接:https://blog.csdn.net/Qinhaifu/article/details/104607722