Skip to content

Commit

Permalink
go implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Apr 25, 2019
1 parent cd48a93 commit a2150f7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 162. Find Peak Element/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package problem162

/* nums[i] ≠ nums[i+1] */
func findPeakElement(nums []int) int {
left, right := 0, len(nums)-1
var mid int
for left < right {
mid = (left + right) / 2
// there must be a peak on the right
// mid+1 won't be out of bound.
if nums[mid+1] > nums[mid] {
left = mid + 1
} else { // there must be a peak on the right
right = mid
}
}
return left
}

0 comments on commit a2150f7

Please sign in to comment.