896. Monotonic Array
Posted jyg694234697
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了896. Monotonic Array相关的知识,希望对你有一定的参考价值。
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array A
is monotone increasing if for all i <= j
, A[i] <= A[j]
. An array A
is monotone decreasing if for all i <= j
, A[i] >= A[j]
.
Return true
if and only if the given array A
is monotonic.
Note:
1 <= A.length <= 50000
-100000 <= A[i] <= 100000
class Solution(object): def isMonotonic(self, A): if (len(A) == 1): return True target_list = [] for i in range(len(A)-1): target_list.append(A[i+1]-A[i]) target_list_stored = sorted(target_list) for j in range(len(target_list_stored)): if target_list_stored[0] <= 0 and target_list_stored[-1] <= 0: return True elif target_list_stored[0] >= 0 and target_list_stored[-1] >= 0: return True else : return False
以上是关于896. Monotonic Array的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 896. Monotonic Array 单调数组
js代码片段: utils/lcoalStorage/cookie
[TIA PORTAL][CONVERT] Convert Char Array to DInt...DInt to Char Array..Useful and easy function(代码片段