*Java* 9 lines 1ms (binary search)


  • 0
    E

    Please leave your comment if any question about this solution :)

    public int findMin(int[] nums) {
    	int L=nums.length, lo=0, hi=L-1;
    	while(lo<=hi) {
    		int mid = lo + ((hi-lo)>>1);
    		if(nums[lo]>nums[hi]) {
    			if(nums[lo]<=nums[mid]) lo = mid+1;
    			else if(mid>=1 && nums[mid]<nums[mid-1]) return nums[mid];
    			else hi = mid-1;
    		}
    		else return nums[lo];
    	}
    	return nums[0];
    }

Log in to reply
 

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