Skip to content

Commit e9a16ca

Browse files
committed
GO: 852. Peak Index in a Mountain Array
1 parent d04b3af commit e9a16ca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func peakIndexInMountainArray(arr []int) int {
2+
left, right := 0, len(arr)-1
3+
res := -1
4+
5+
for left <= right {
6+
mid := left + (right-left+1)/2
7+
8+
if arr[mid-1] <= arr[mid] {
9+
left, res = mid+1, mid
10+
} else {
11+
right = mid - 1
12+
}
13+
}
14+
15+
return res
16+
}

0 commit comments

Comments
 (0)