Simple Java code O(n)

  • -2
    public class Solution {
        public int findMin(int[] nums) {
            int min = nums[0];
            for(int i = 0 ; i < nums.length -1 ; i ++){
                int current = nums[i];
                int nextcurr = nums[i+1];
                if(nextcurr < current) return nextcurr;
            return min;

    Since the array was previously sorted, so we will be able to know the minimum integer will be in two situations:

    1. The head of the array (which means no rotations)
    2. Right after of the end of first ascending list. (i.e. 4,5,6,1,2,3)

  • 0

    This is acceptable in logic, but not really good for the purpose which is to solve this question using binary search

Log in to reply

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