Check if array is monotone increasing or decreasing.
class Solution:
def isMonotonic(self, nums: List[int]) -> bool:
n = len(nums)
increasing = decreasing = True
for i in range(1, n):
if nums[i] < nums[i-1]:
increasing = False
if nums[i] > nums[i-1]:
decreasing = False
if not increasing and not decreasing:
return False
return True
Check if array is monotone increasing or decreasing.