Very Simple Solution beats 90% java solutions


  • 0
    S

    Just check when the array decreases instead of increasing (as it is sorted) , and if that doesnt happen , rotation is 0 , so return the first element as min :)
    assumption : there is at least 1 element in array . ( we can put a simple length check for this is needed)

    assum

     public int findMin(int[] nums) {
            for(int i = 1; i < nums.length; i++){
                if(nums[i] < nums[i-1]){
                    return nums[i];
                }  
            }
            return nums[0];
        }
    

Log in to reply
 

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