A java solution with O(logN)


  • 0
    Y

    public class Solution {
    public int findMin(int[] nums) {
    int l = 0,r=nums.length-1;
    if(nums.length == 1)
    {
    return nums[0];
    }
    if(nums[0] < nums[nums.length-1])
    {
    return nums[0];
    }
    while(l<=r)
    {
    int mid = (l+r)/2;
    if(mid>0 && nums[mid]<nums[mid-1])
    {
    return nums[mid];
    }
    else if(nums[mid] < nums[r])
    {
    r = mid-1;
    }
    else
    {
    l = mid+1;
    }
    }
    return -1;
    }

    }


Log in to reply
 

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