leetcode 152&153 Find Minimum in Rotated Sorted Array

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.
You may assume no duplicate exists in the array.
1 | class Solution { |
- 每次和最后一个元素比较。
- 1 2 3 -> s 1, e 3, m 2 -> s 1, e 1
- 3 2 1 -> s 3, e 1, m 2 -> s 2, e 1 -> s 2 e 1 m 2 -> s 1 e 1
what if there is duplicate items,
1 | class Solution { |
- example: 3, 3, 1, 3
- 当出现这种情况时,mid == end, 需要end–