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.
The array may contain duplicates.
Example 1:
Input: [1,3,5]
Output: 1
Example 2:
Input: [2,2,2,0,1]
Output: 0
Note:
This is a follow up problem to Find Minimum in Rotated Sorted Array.
Would allow duplicates affect the run-time complexity? How and why?
在153题的基础之上、增加了重复数字
思路:
1、产生的主要问题是:我们没有办法处理相等的情况、也就是说相等的话:我们并不能确定最小值在mid的左边还是右边
2、第一种方法:一个个排除、虽然不能确定左右、但是既然两者相等、我们便可以让end--、把最后一位排除掉、因为有相等的值、排除也无所谓。
3、这样子便证明了重复的数字的确影响了时间复杂度、我们并不能够百分之百确认左右的时候。其实就是一一遍历、接近于O(n)的复杂度。