📜  在数组中透视 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:08.813000             🧑  作者: Mango

代码示例1
// https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
// assuming Array has no duplicates
class Solution {
    public int findMin(int[] nums) {
        int start = 0;
        int end  = nums.length-1;
        
        while (start < end){
            int mid = start + (end-start)/2;
            if (nums[mid] > nums[end]) start = mid+1;
            if (nums[mid] < nums[end]) end = mid;
        }
        return nums[start];
    }
}