leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0852.cpp (445B)


      1 class Solution {
      2   public:
      3     int peakIndexInMountainArray(const vector<int> &arr) {
      4         int low = 1, high = arr.size() - 2;
      5         while (low <= high) {
      6             int mid = low + (high - low) / 2;
      7             if (arr[mid - 1] < arr[mid] && arr[mid] > arr[mid + 1]) return mid;
      8             if (arr[mid - 1] < arr[mid])
      9                 low = mid + 1;
     10             else
     11                 high = mid - 1;
     12         }
     13         return -1;
     14     }
     15 };