public int findPeak(int[] nums) {
int l = 0, r = nums.length - 1;
while (l < r) {
int mid = (l + r) / 2;
if (nums[mid] > nums[mid + 1] && nums[mid] > nums[mid - 1]) {
return mid;
} else if (nums[mid] < nums[mid - 1]) {
r = mid ;
} else if (nums[mid] > nums[mid - 1]) {
l = mid;
}
}
return l;
LintCode :Find Peak Element
最新推荐文章于 2023-03-08 15:56:54 发布