👨🏫 33. 搜索旋转排序数组
class Solution {public int search(int[] nums, int target){int l = 0;int r = nums.length - 1;while (l <= r){int m = l + r >> 1;//else大法,把无序段抛给else,if只处理有序段 // 需要特殊处理 中间值if (nums[m] == target)return m;if (nums[l] <= nums[m])// 说明 left 到 mid 有序{if (target >= nums[l] && target < nums[m])// mid点已经在前边特判了r = m - 1;elsel = m + 1;}else// 说明 mid+1 到 right 是有序的{if (target > nums[m] && target <= nums[r])// mid点已经在前边特判了l = m + 1;else{r = m - 1;}}}return -1;}
}