假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2)。
你需要找到其中最小的元素。
你可以假设数组中不存在重复的元素。
样例
给出[4,5,6,7,0,1,2] 返回 0
public class Solution {
/**
* @param num: a rotated sorted array
* @return: the minimum number in the array
*/
public int findMin(int[] num) {
if(num == null || num.length == 0) return -1;
int l = 0;
int r = num.length - 1;
while(l < r) {
int m = l + (r - l)/2;
if(num[m] < num[r]) {
r = m;
}else {
l = m + 1;
}
}
return num[l];
}
}