896. Monotonic Array
Easy
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array nums
is monotone increasing if for all i <= j
, nums[i] <= nums[j]
. An array nums
is monotone decreasing if for all i <= j
, nums[i] >= nums[j]
.
Given an integer array nums
, return true
if the given array is monotonic, or false
otherwise.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 105
-105 <= nums[i] <= 105
解題
O(n)
Runtime: 152 ms, faster than 85.47%
Memory Usage: 9.2 MB, less than 77.78%
Previous889. Construct Binary Tree from Preorder and Postorder TraversalNext897. Increasing Order Search Tree
Last updated