2
public boolean search(int[] nums, int target) {3
if (nums == null || nums.length == 0) return false;5
int left = 0, right = nums.length - 1;8
// 1. find index of the smallest element10
while (left < right && nums[left] == nums[left + 1]) ++left;11
while (left < right && nums[right] == nums[right - 1]) --right;12
int mid = left + (right - left) / 2;13
if (nums[mid] > nums[right]) {18
// 2. figure out in which side our target lies21
right = nums.length - 1;22
if (target >= nums[start] && target <= nums[right]) left = start;25
// 3. Run normal binary search in sorted half.26
while (left <= right) {27
int mid = left + (right - left) / 2;28
if (nums[mid] == target) return true;30
if (nums[mid] > target) right = mid - 1;