162. 寻找峰值

162. 寻找峰值

解法一: 半分查找

go
1
2
3
4
5
6
7
8
9
10
11
12
13
func findPeakElement(nums []int) int {
left := 0
right := len(nums) - 1
for left < right {
mid := ((right - left) >> 1) + left
if nums[mid] < nums[mid + 1] {
left = mid + 1
} else {
right = mid
}
}
return left
}
作者

wuhunyu

发布于

2023-12-18

更新于

2023-12-18

许可协议