Find Minimum in Rotated Sorted Array II
Problem: Find Minimum in Rotated Sorted Array II
Duplicate numbers won't interfere too much to the algorithm. We only to worry about what will happen if the middle number equals the end number. If this happens, we simply ignore the last number and do comparison with the second last number and do this repeatedly if several duplicates happen.
Code in Python:
class Solution(object):
def findMin(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
l, r = 0, len(nums)-1
while l < r:
mid = (l + r) / 2
if nums[mid] < nums[r]:
r = mid
elif nums[mid] > nums[r]:
l = mid + 1
else:
r -= 1
return nums[r]