# 896. Monotonic Array

判断数组是否有单调性。遍历并用一个变量记录遇到的单调性，当遇到不满足已记录的单调性的元素时返回false。

```
/*
 * @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


```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hao-fu-1.gitbook.io/oj/array_and_numbers/896.-monotonic-array.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
