Leetcode 932 Solution

This article provides solution to leetcode question 932 (monotonic-array)

https://leetcode.com/problems/monotonic-array

Solution

class Solution(object):
    def isMonoIncreasing(self, A):
        for i in range(len(A) - 1):
            if A[i] > A[i + 1]:
                return False
        return True

    def isMonoDecreasing(self, A):
        for i in range(len(A) - 1):
            if A[i] < A[i + 1]:
                return False
        return True

    def isMonotonic(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        return self.isMonoIncreasing(A) or self.isMonoDecreasing(A)