# Leetcode 162 - Find peak element

Note:

• By the description, we need to use binary search.
• But the array is not sorted, how should we know which direction we need to move?
• Always move toward the element with bigger value!
• Imagine we always do this, eventually when we hit 0 or len - 1, both nums[-1] or nums[len] are -Infinity. We can definitely get nums[i] bigger than its neighbors.

Question:

A peak element is an element that is strictly greater than its neighbors.

Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

You may imagine that nums[-1] = nums[n] = -∞.

You must write an algorithm that runs in O(log n) time.

Example:

Code: