标签:
Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?Would this affect the run-time complexity? How and why?
Suppose a sorted array 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.
The array may contain duplicates.
由于可能存在相同元素,所以我们不能直接使用二分搜索法,如果左端和右端都是一样的元素的话我们无法在logn的复杂度下完成对下列情况的判断。
[9,9,9,1,9] [9,1,9,9,9]
,所以对本题用线性算法解决即可。
leetcode-Find Minimum in Rotated Sorted Array II
标签:
原文地址:http://www.cnblogs.com/nano94/p/4346001.html