153. Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,1,2,4,5,6,7]
might become [4,5,6,7,0,1,2]
).
Find the minimum element.
You may assume no duplicate exists in the array.
Example 1:
Example 2:
Thoughts:
Binary Search:
1st method : To find the minimum, use the nums[mid] to compare with nums[right]:
2nd method: To compare with nums[left] and at the end compare the found result with start and end value (since this method would "assume there is a pivot")
Code1:
Code2:
Last updated
Was this helpful?