Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int peakIndexInMountainArray(vector<int>& A) {
- int left = 0;
- int right = A.size()-1;
- while (left <= right) {
- int mid = left + (right - left) / 2;
- if (A[mid - 1] < A[mid] && A[mid + 1] < A[mid]) {
- return mid;
- }
- if (A[mid] < A[mid + 1]) {
- left = mid + 1;
- } else {
- right = mid - 1;
- }
- }
- return 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement