Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MinimumInRotatedArray {
- /**
- * The function returns the minimum number of an
- * arbitrary number of rotated sorted array using
- * binary search. Hence, the time complexity is O(LogN)
- * and space complexity is O(1)
- * @param nums the rotated sorted array
- * @return minimum number in the array
- */
- public int findMin(int[] nums) {
- var start = 0;
- var end = nums.length - 1;
- while (start < end) {
- var mid = start + ((end - start) >> 1);
- if (nums[mid] > nums[end]) {
- start = mid + 1;
- } else {
- end = mid;
- }
- }
- return nums[start];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement