Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?算法Would this affect the run-time complexity? How and why?this
Suppose a sorted array is rotated at some pivot unknown to you beforehand.spa
(i.e., 0 1 2 4 5 6 7
might become 4 5 6 7 0 1 2
).code
Find the minimum element.element
The array may contain duplicates.it
因爲可能存在相同元素,因此咱們不能直接使用二分搜索法,若是左端和右端都是同樣的元素的話咱們沒法在logn的複雜度下完成對下列狀況的判斷。搜索
[9,9,9,1,9] [9,1,9,9,9] im
,因此對本題用線性算法解決便可。sort