public int mountainSequence(int[] nums) {
if (nums == null || nums.length == 0) {
return Integer.MIN_VALUE;
}
if (nums.length == 1) {
return nums[0];
}
if (nums[0] > nums[1]) {
return nums[0];
}
if (nums[nums.length - 2] < nums[nums.length - 1]) {
return nums[nums.length - 1];
}
int start = 1;
int end = nums.length - 2;
while (start + 1 < end) {
int mid = start + (end - start) / 2;
if (nums[mid] > nums[mid - 1] && nums[mid] > nums[mid + 1]) {
return nums[mid];
} else if (nums[mid] > nums[mid - 1] && nums[mid] < nums[mid + 1]) {
start = mid;
} else {
end = mid;
}
}
}