from typing import List
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
n = len(A)
i = 1
while i < n:
if A[i] > A[i-1]:
break
i += 1
if i == n:
return True
i = 1
while i < n:
if A[i] < A[i-1]:
break
i += 1
if i == n:
return True
return False
from typing import List
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
n = len(A)
trend = 0
for i in range(1, n):
if trend == 0:
if A[i] > A[i-1]:
trend = 1
elif A[i] < A[i-1]:
trend = -1
elif trend * (A[i] - A[i-1]) < 0:
return False
return True
from typing import List
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
return not {(x>y) - (y>x) for x, y in zip(A, A[1:])} >= {1, -1}