leetcode

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

0896.cpp (347B)


      1 class Solution {
      2   public:
      3     bool isMonotonic(const vector<int> &nums) {
      4         bool inc = false, dec = false;
      5         for (int i = 1; i < nums.size(); i++) {
      6             if (nums[i] > nums[i - 1]) dec = true;
      7             if (nums[i] < nums[i - 1]) inc = true;
      8             if (dec && inc) break;
      9         }
     10         return !(dec & inc);
     11     }
     12 };