#896

Monotonic Array

pupil · 355 · lc easy +23 · verified · 62.2% accepted · 3,268 likes · top 63%

Description

An integer array is monotonic if it never changes direction — it either stays non-decreasing throughout or non-increasing throughout.

Given an integer array nums, return true if nums is monotonic, or false otherwise.

Example 1:

Input: nums = [1,2,2,3]
Output: true

Example 2:

Input: nums = [6,5,4,4]
Output: true

Example 3:

Input: nums = [1,3,2]
Output: false

Code

1
2
3