We use binary search for this question.

There are 4 scenarios to consider:

- mid is at the lowest
- mid is at peak
- mid is at the increasing slope
- mid is at the decreasing slope.

Use the following algorithm we can achieve O(logn) time complexity and O(1) space complexity.

```
public class Solution {
public int findPeakElement(int[] nums) {
//corner case
if (nums.length==0 || nums==null){
return 0;
}
int start=0;
int end= nums.length-1;
while(start+1<end){
int mid = start+ (end-start)/2;
//peak
if(nums[mid]>nums[mid-1] && nums[mid]>nums[mid+1]){
return mid;
}
//decreasing
else if(nums[mid]<nums[mid-1]){
end=mid;
}
//increaseing : A[mid] > A[mid - 1]
//lowest : A[mid] < A[mid - 1] && A[mid] < A[mid + 1]
else{
start=mid;
}
}
if(nums[start]>nums[end]){
return start;
}
else{
return end;
}
}
}
```