Skip to content
LC-0896 Easy LeetCode

896. Monotonic Array

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 62% Topics: Array
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def isMonotonic(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        inc, dec = False, False
        for i in xrange(len(A)-1):
            if A[i] < A[i+1]:
                inc = True
            elif A[i] > A[i+1]:
                dec = True
        return not inc or not dec

Solution from kamyu104/LeetCode-Solutions · MIT