首页 > 其他 > 详细

896. Monotonic Array

时间:2020-07-02 21:15:03      阅读:63      评论:0      收藏:0      [点我收藏+]

An array is monotonic if it is either monotone increasing or monotone decreasing.

An array A is monotone increasing if for all i <= jA[i] <= A[j].  An array A is monotone decreasing if for all i <= jA[i] >= A[j].

Return true if and only if the given array A is monotonic.

判断一个数列是否单调,on直接做就行

class Solution(object):
    def isMonotonic(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        incre = True
        descre = True
        for i in range(1, len(A), 1):
            if A[i] < A[i - 1]:
                incre = False
            if A[i] > A[i - 1]:
                descre = False
        return incre | descre

 

896. Monotonic Array

原文:https://www.cnblogs.com/whatyouthink/p/13226750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!