Find Minimum in Rotated Sorted Array(寻找旋转排序数组中的最小值)

问题

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.
Notice
You may assume no duplicate exists in the array.
Example
Given [4, 5, 6, 7, 0, 1, 2] return 0

分析

请参阅 寻找旋转排序数组中的最小值 II

代码

    /**
     * @param nums: a rotated sorted array
     * @return: the minimum number in the array
     */
    public int findMin(int[] nums) {
        // write your code here
        int l=0;
        int r=nums.length-1;
        while(lnums[mid]){
                r=mid;
            }else{
                l=mid+1;
            }
        }
        return nums[l];
    }
}

你可能感兴趣的:(Find Minimum in Rotated Sorted Array(寻找旋转排序数组中的最小值))