1ms Java nlog(n) solution

  • 0
    public int findMin(int[] nums) {
            return findIt(nums,0,nums.length-1);
    public int findIt(int[] nums,int left,int right){
         if(left>right) return -1;
         if(left==right) return nums[left];
         int mid = left+(right-left)/2;
         if(mid==left) return nums[mid]<nums[right]? nums[mid]:nums[right];
             else if(mid!=left&&mid!=right&&
    nums[mid]<nums[mid-1]&&nums[mid]<nums[mid+1]) return nums[mid];
                else if(nums[right]<nums[mid]) {
                    return findIt(nums,mid+1,right);
                     return findIt(nums,left,mid-1);

Log in to reply

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