Medium
, Binary Search
Question
接Find Minimum in Rotated Sorted Array,
假设有重复数字。
Solution
解法依然是二分搜索,不过多了一种情况要考虑。
class Solution(object):
def findMin(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
L, R = 0, len(nums)-1
while L<R and nums[L]>=nums[R]:
M = (L+R)/2
if nums[M]>nums[R]:
L = M+1
elif nums[M]<nums[L]:
R = M
else:
L = L+1
return nums[L]
网友评论