Description
An array is monotonic if it is either entirely non-increasing or entirely non-decreasing. Given an integer array nums, return true if the array is monotonic, false otherwise.
Examples
Input:
nums = [1,2,2,3]Output:
trueExplanation:
Non-decreasing.
Input:
nums = [6,5,4,4]Output:
trueExplanation:
The array is monotonically non-increasing: 6 >= 5 >= 4 >= 4.
Input:
nums = [1,3,2]Output:
falseExplanation:
The array is neither non-increasing nor non-decreasing: 1 < 3 but 3 > 2.
Constraints
- •
1 ≤ nums.length ≤ 10⁵