```
int findPeakElement(const vector<int> &num) {
int n = num.size();
// check first element & last element
if (n == 1 || num[0] > num[1]) {
return 0;
} else if (num[n-1] > num[n-2]) {
return n-1;
}
int l = 1;
int h = n-2;
while(l < h) {
int mid = (l+h)/2;
if (num[mid] > num[mid-1] && num[mid] > num[mid+1]) {
return mid;
} else if (num[mid] < num[mid+1]) {
l = mid+1;
} else {
h = mid-1;
}
}
}
```