Skip to content

LC 0896 [E] Monotonic Array

Code with Senpai edited this page Oct 21, 2022 · 5 revisions

is it either an increasing or decreasing monotonic array?

n-1 so we can track i+1

class Solution:
    def isMonotonic(self, A: List[int]) -> bool:
        inc = dec = True
        
        for i in range(len(A) - 1):
            if A[i] > A[i+1]:
                inc = False
            if A[i] < A[i+1]:
                dec = False
                
        return inc or dec
Clone this wiki locally