```
class Solution {
public:
int findPeakElement(vector<int>& nums)
{
if(nums.size() <= 1)
return 0;
return peakIndex(nums, 0, nums.size() - 1);
}
int peakIndex(vector<int>& nums, int begin, int end)
{
if(begin > end)
return -1;
int mid = (begin + end) / 2;
int left = (mid - 1) < 0 ? INT_MIN : nums[mid - 1];
int right = (mid + 1) > (nums.size() - 1) ? INT_MIN : nums[mid + 1];
if(nums[mid] > right && nums[mid] > left)
return mid;
if(mid > 0 && nums[mid - 1] > nums[mid])
return peakIndex(nums, begin, mid - 1);
else
return peakIndex(nums, mid + 1, end);
}
};
```