[Java] Concise solution + explanation

  • 0
    • A subarray of a rotated sorted array is also a rotated sorted array.
    • If the first value of such an array is smaller than the last value, then it is the smallest value.
    public class Solution {
        public int findMin(int[] nums) {
            return findMin(0, nums.length - 1, nums);
        public int findMin(int start, int end, nums) {
            if (start == end) return nums[start];
            if (nums[start] < nums[end]) return nums[start];
            int mid = start + (end-start)/2;
            return Math.min(findMin(start, mid, nums), findMin(mid+1, end, nums));

Log in to reply

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