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.

Note:

  1. 1 <= A.length <= 50000
  2. -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的更多相关文章

  1. 896. Monotonic Array@python

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

  2. 【Leetcode_easy】896. Monotonic Array

    problem 896. Monotonic Array solution1: class Solution { public: bool isMonotonic(vector<int>& ...

  3. [LeetCode] 896. Monotonic Array 单调数组

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

  4. LeetCode 896 Monotonic Array 解题报告

    题目要求 An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is ...

  5. [LeetCode&Python] Problem 896. Monotonic Array

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

  6. 896. Monotonic Array单调数组

    [抄题]: An array is monotonic if it is either monotone increasing or monotone decreasing. An array A i ...

  7. LeetCode 896. Monotonic Array

    原题链接在这里:https://leetcode.com/problems/monotonic-array/ 题目: An array is monotonic if it is either mon ...

  8. 【LeetCode】896. Monotonic Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. LeetCode 896. 单调数列(Monotonic Array)

    896. 单调数列 896. Monotonic Array 题目描述 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i<=j,A[i]<=A[j],那么数组 A 是单调 ...

随机推荐

  1. [Android]简略的Android消息机制源码分析

    相关源码 framework/base/core/java/andorid/os/Handler.java framework/base/core/java/andorid/os/Looper.jav ...

  2. luogu P4145 上帝造题的七分钟2 / 花神游历各国 维护区间和&&区间开根号

    因为开根号能使数字减小得非常快 所以开不了几次(6次?)很大的数就会变成1..... 所以我们可以维护区间最大值,若最大值>1,则继续递归子树,暴力修改叶节点,否则直接return (好像也可以 ...

  3. Uva12210-A Match Making Problem

    对于每个数字二分找到大于等于它的数,再暴力找到第一个小于它的数 #include<bits/stdc++.h> #define inf 0x3f3f3f3f ; using namespa ...

  4. 获取所有bean的名字

    import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.facto ...

  5. csu 1554: SG Value 思维题

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作, ...

  6. linux打包文件,压缩文件

    1.打包: linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进行压缩. 1.命令格 ...

  7. C#基础之运行环境

    这是我的第一篇博文,目前这一阶段我的目标是先把C#掌握好,C#是一门语言,是基于C风格语言(C.C++和Java)的特性而设计的.所以在我的博客里,我会记录下我的学习笔记,这不仅仅是笔记,还是所学过的 ...

  8. js 回车提交表单

    一.整个页面用一个回车提交事件: <input type="button" value="回车提交" id="auto" onclic ...

  9. 通用的ashx调用

    直接上代码 还是有一定通用性的 <%@ WebHandler Language="C#" Class="MyService" %> using Sy ...

  10. c# Redis操作类

    需要添加StackExchange.Redis.dll引用 using System; using System.Collections.Generic; using System.IO; using ...