package leetcode;

/**
 * https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
 */
public class Problem153 {
    public int findMin(int[] nums) {
        int min = nums[0];
        for (int n : nums) {
            if (n < min) {
                min = Math.min(n, min);
            }
        }
        return min;
    }
}

@@ -166,24 +166,175 @@
     
-int min =
+return findMin(nums, 0, nums.length-1);%0A    %7D%0A    %0A    private int findMin(int%5B%5D nums, int left, int right) %7B%0A        if (left %3E= right) %7B%0A            return
  nums%5B
-0
+left
 %5D;%0A 
@@ -344,139 +344,604 @@
     
-for (int n : nums) %7B%0A            if (n %3C min) %7B%0A                min = Math.min(n, min);%0A            %7D%0A        %7D%0A        return min;
+%7D%0A        int mid = (left + right) / 2;%0A        int minLeft = nums%5Bleft%5D;%0A        if (mid-1 %3E= 0) %7B%0A            minLeft = Math.min(minLeft, nums%5Bmid-1%5D);%0A        %7D%0A        int minRight = nums%5Bright%5D;%0A        if (mid+1 %3C nums.length) %7B%0A            minRight = Math.min(minRight, nums%5Bmid+1%5D);%0A        %7D%0A        int min = Math.min(minLeft, Math.min(nums%5Bmid%5D, minRight));%0A        if (min == nums%5Bmid%5D) %7B%0A            return nums%5Bmid%5D;%0A        %7D%0A        if (minLeft %3C minRight) %7B%0A            return findMin(nums, left, mid-1);%0A        %7D else %7B%0A            return findMin(nums, mid+1, right);%0A        %7D
 %0A   

Solve problem 153 (log n)