896. Monotonic Array
https://leetcode.com/problems/monotonic-array/
/*
* @lc app=leetcode id=896 lang=cpp
*
* [896] Monotonic Array
*/
// @lc code=start
class Solution {
public:
bool isMonotonic(vector<int>& A) {
if (A.size() <= 1) return true;
int inc = 0;
for (int i = 1; i < A.size(); ++i) {
if (A[i] < A[i - 1]) {
if (inc == 1) return false;
inc = -1;
} else if (A[i] > A[i - 1]) {
if (inc == -1) return false;
inc = 1;
}
}
return true;
}
};
// @lc code=end
Previous1007. Minimum Domino Rotations For Equal RowNext1333. Filter Restaurants by Vegan-Friendly, Price and Distance
Last updated