Posted on

Description

Submission

class Solution {
public:
    bool isMonotonic(vector<int>& A) {
        if(A.size() == 1) return true;
        
        int i = 1;
        for(; i < A.size(); ++i) {
            if(A[i-1] > A[i]) break;
        }
        if(i == A.size()) return true;

        for(i = 1; i < A.size(); ++i) {
            if(A[i-1] < A[i]) break;
        }
        if(i == A.size()) return true;

        return false;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *