Question
Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., ​`​0 1 2 4 5 6 7​`​​ might become ​`​4 5 6 7 0 1 2​`​).

Find the minimum element.

You may assume no duplicate exists in the array.

【复杂度】

【思路】

【代码】

`public class Solution {    public int findMin(int[] nums) {        return helper(0,nums.length-1,nums);    }    private int helper(int l,int r,int[] nums){        //base case        if(r==l)return nums[l];        int mid=(l+r)/2;        if(nums[r]>nums[mid])            return helper(l,mid,nums);        else            return helper(mid+1,r,nums);    }}`

【Follow Up】

`public class Solution {    public int findMin(int[] nums) {        return helper(0,nums.length-1,nums);    }    private int helper(int l,int r,int[] nums){        //base case        if(r==l)return nums[l];        int mid=(l+r)/2;        if(nums[l]>=nums[mid])            if(nums[r]>=nums[mid])return helper(l,mid,nums);            else                 return helper(mid+1,r,nums);        else            if(nums[r]<=nums[mid])return helper(mid+1,r,nums);            else                 return helper(l,mid,nums);    }}`

## 参考

​​[Leetcode] Find Minimum in Rotated Sorted Array 找旋转有序数组的最小值​​