Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int peakIndexInMountainArray(vector<int>& A) {
  4. int left = 0;
  5. int right = A.size()-1;
  6.  
  7. while (left <= right) {
  8. int mid = left + (right - left) / 2;
  9. if (A[mid - 1] < A[mid] && A[mid + 1] < A[mid]) {
  10. return mid;
  11. }
  12. if (A[mid] < A[mid + 1]) {
  13. left = mid + 1;
  14. } else {
  15. right = mid - 1;
  16. }
  17. }
  18.  
  19. return 0;
  20. }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement