Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Find Minimum in Rotated Sorted Array

// https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
// assuming Array has no duplicates
class Solution {
    public int findMin(int[] nums) {
        int start = 0;
        int end  = nums.length-1;
        
        while (start < end){
            int mid = start + (end-start)/2;
            if (nums[mid] > nums[end]) start = mid+1;
            if (nums[mid] < nums[end]) end = mid;
        }
        return nums[start];
    }
}
 
PREVIOUS NEXT
Tagged: #Find #Minimum #Rotated #Sorted #Array
ADD COMMENT
Topic
Name
7+9 =