dsa · easy
Find Peak Element
GreyOrangeArrayBinary SearchFoundation
A peak is an element strictly greater than its neighbors (ends compare with one neighbor). Return **any** peak index.
Arguments
nums— the input array of integers
**Example:** [1,2,3,1] → 2.
Constraints
1 <= nums.length <= 1000; a peak always exists Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,2,3,1] Expected: 2
Example 2
Input: [1] Expected: 0