Java | TC: O(logN) | SC: O(1) | Optimal Binary Search with Early Exit
java\n/**\n * Modified Binary Search\n *\n * Time Complexity: O(log N)\n *\n * Space Complexity: O(1)\n *\n * N = Length of the input array.\n */\nclass Solutio
```java\n/**\n * Modified Binary Search\n *\n * Time Complexity: O(log N)\n *\n * Space Complexity: O(1)\n *\n * N = Length of the input array.\n */\nclass Solution {\n    public int findMin(int[] nums) {\n        if (nums == null || nums.length == 0) {\n            throw new IllegalArgumentException("Input is invalid");\n        }\n\n        int len = nums.length;\n        if (len == 1 || nums[0] < nums[len - 1]) {\n            return nums[0];\n        }\n        if (len == 2) {\n            return Math.min(nums[0], nums[1]);\n        }\n\n        int start = 0;\n        int end = len - 1;\n\n        while (start < end) {\n            if (nums[start] < nums[end]) {\n                return nums[start];\n            }\n\n            int mid = start + (end - start) / 2;\n            if (nums[mid] <= nums[end]) {\n                end = mid;\n            } else {\n                start = mid + 1;\n            }\n        }\n\n        return nums[start];\n    }\n}\n```\n\n---\n\nSolutions to other Rotated Sorted Array questions on LeetCode:\n- [33. Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/discuss/1529302/Java-or-TC:-O(logN)-or-SC:-O(1)-or-Modified-Binary-Search-optimal-solution)\n- [81. Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/discuss/1529305/Java-or-TC:-O(N2)-or-SC:-O(1)-or-Modified-Binary-Search-optimal-solution)\n- [154. Find Minimum in Rotated Sorted Array II + FollowUp](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1529323/Java-or-TC:-O(N2)-or-SC:-O(1)-or-Optimal-Binary-Search-w-Early-Exit-and-FollowUp)\n
['Array', 'Binary Tree', 'Java']