Java 0ms Avoid Check the First Element


  • 0
    public int findMin(int[] nums) {
        int len = nums.length;
        if(nums == null || len == 0) return 0;
        int l = 0 , r = len-1;
        int mid =0;
        while(l<=r)
        {
            mid = l + (r-l)/2;
            if(nums[mid] >= nums[len-1]) l = mid+1;
            else r = mid -1; 
        }
        return nums[mid]>nums[len-1]?nums[mid+1] : nums[mid];
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.