154. Find Minimum in Rotated Sorted Array II

# Hard

Same as #81.

Solution 1:

  1. consider the edge case: 1 element

  2. skip repeated element at the beginning and end

  3. find the pivot

  4. get result under 2 situations

Solution 2:

  1. remove same element from end

  2. find the pivot

// Java O(logN) solusion
class Solution {
    public int findMin(int[] nums) {
        int start = 0, end = nums.length - 1;
        while(end > 0) {
            if(nums[end] != nums[start])
                break;
            end --;
        }
        
        while(start < end) {
            int mid = start + (end - start)/2;
            if(nums[mid] > nums[end])
                start = mid + 1;
            else
                end = mid;
        }
        
        return nums[start];
    }
}

Last updated