leetcode

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

0941.cpp (380B)


      1 class Solution {
      2   public:
      3     bool validMountainArray(vector<int> &arr) {
      4         int i = 0;
      5         while (i < arr.size() - 1 && arr[i] < arr[i + 1])
      6             i++;
      7 
      8         if (i == 0) return false;
      9 
     10         int j = i;
     11         while (i < arr.size() - 1 && arr[i] > arr[i + 1])
     12             i++;
     13 
     14         if (i == j) return false;
     15 
     16         return i == arr.size() - 1;
     17     }
     18 };