binary search solution(java)

  • 0

    use the binary search to keep the array always being rotated, so the min is alway in the left array till there is only one element.

    public class Solution {
        public int findMin(int[] nums) {
            int left=0;
            int right=nums.length-1;     
                int mid=left+(right-left)/2;
                if(nums[mid]>nums[right]){  //mid is possible equal to mid
                    right=mid;  //mid could the the final result ,so mid-1 is wrong
            return nums[left];

Log in to reply

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