二分查找
public class Solution {
public int findMin(int[] num) {
if (num == null || num.length == 0) {
return -1;
}
if (num[0] < num[num.length - 1]) {
return num[0];
}
int leftIndex = 0;
int rightIndex = num.length - 1;
while (rightIndex > leftIndex) {
int midIndex = (leftIndex + rightIndex) / 2;
if (midIndex == leftIndex) {
return num[rightIndex];
}
if (num[midIndex] > num[rightIndex]) {
leftIndex = midIndex;
} else if (num[midIndex] < num[rightIndex]) {
rightIndex = midIndex;
} else {
return num[midIndex];
}
}
return num[rightIndex];
}
}