lc-go/solutions/8/q852/solution.go
2026-03-19 15:30:30 +09:00

17 lines
347 B
Go

// Package q852 implements a solution for https://leetcode.com/problems/peak-index-in-a-mountain-array/
package q852
func peakIndexInMountainArray(arr []int) int {
l, r := 0, len(arr)-1
for l < r {
m := (l + r) / 2
if arr[m] < arr[m+1] { // incrementing
l = m + 1
} else {
r = m
}
}
return l
}
var _ = peakIndexInMountainArray