Easy
Monotonic Array — Python
Full explanation · Time O(n) · Space O(1)
# 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