Monotonic Array
Problem statement
Return whether nums is monotone. It is monotone when it is entirely nondecreasing or entirely nonincreasing.
Function
isMonotonic(nums: int[]) → booleanExamples
Example 1
nums = [1,2,2,3]return = trueThe array is nondecreasing.
Example 2
nums = [1,3,2]return = falseThe direction changes.
Constraints
1 <= nums.length <= 10^5.- Values are 32-bit signed integers.