binary search


  • 0
    X

    concise binary solution:

    public int findMin(int[] nums) {
    if(nums == null || nums.length == 0) return 0;

        int low = 0;
        int high = nums.length - 1;
        while(low < high){
        	int mid = (low + high)/2;
        	if(nums[high] < nums[mid]){
        		low = mid + 1;
        	}else {
        		high = mid;
        	}
        }
    
        return nums[low];
    }

Log in to reply
 

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