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

 

思路:二分查找

// @Title: 寻找旋转排序数组中的最小值 (Find Minimum in Rotated Sorted Array)
// @Author: qisiii
// @Date: 2022-02-20 11:52:08
// @Runtime: 0 ms
// @Memory: 41.2 MB
// @comment: 二分查找
// @flag: BLUE
class Solution {
    public int findMin(int[] nums) {
        int left=0;
        int right=nums.length-1;
        while(left<right){
            int mid=left+(right-left)/2;
            if(nums[mid]<nums[right]){
                right=mid;
            }else {
                left=mid+1;
            }
        }
        return nums[right];
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18