896. 单调数列
1 class Solution(object): 2 def isMonotonic(self, A): 3 """ 4 :type A: List[int] 5 :rtype: bool 6 """ 7 i = 1 8 while i < len(A): 9 if A[i] == A[i - 1]: 10 i += 1 11 # 递增 12 elif A[i] > A[i - 1]: 13 for j in range(i, len(A)): 14 if A[j] < A[j - 1]: 15 return False 16 break 17 # 递减 18 elif A[i] < A[i - 1]: 19 for j in range(i, len(A)): 20 if A[j] > A[j - 1]: 21 return False 22 break 23 return True 24 25 26 if __name__ == '__main__': 27 solution = Solution() 28 print(solution.isMonotonic([-1, -1, -1, -9, 2]))