81

 

 

Code:

public boolean search(int[] nums, int target) {
    if (nums.length == 0){
        return false;
    }

    int left = 0, right = nums.length - 1;

    while (left <= right){
        int mid = left + (right - left) / 2;
        if (nums[mid] == target) return true;

        if (nums[left] == nums[mid] && nums[mid] == nums[right]) {left++; right--;}
        else if (nums[mid] <= nums[right]){
            if (nums[mid] < target && nums[right] >= target)  left = mid + 1;
            else right = mid -1;
            }
        else {
            if (nums[left] <= target && nums[mid] > target) right = mid -1;
            else left = mid + 1;
            }
        }
    return false;
}

  

  

 

上一篇:HT图形组件设计之道(一)


下一篇:Leetcode_med 81. 搜索旋转排序数组 II