Very Easy Java Solutions


  • 0
    J

    This is very straightforward Java solution, according to the questions, you just need to consider these border case:

    [1] [2,1,2,2,2,2] [2,3,1] [2,3,4,5,1,2] [1,2,3,1,1]

    public int findMin(int[] nums) {
        int start = 0, end = nums.length - 1;
        for (int index = 0; index < nums.length; index++){
            if (nums[start] > nums[end]){
                start++;
            } else if (end > 0 && nums[end - 1] <= nums[end]){
                end--;
            } else{
                return nums[start];
            }
        }
        return nums[0];
    }

Log in to reply
 

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