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. STP-12-MST工作原理

    MST将网络划分为一或多个区域.一个MST区域是一组以相同方式共同使用MST的交换机——除了其他特性外,它们运行相同数量的MST实例,并在这些实例上映射相同的VLAN集合. 例如,在下图中,工程师定义 ...

  2. redis 拒绝远程访问解决

    启动时报的警告: 1.Warning: no config file specified, using the default config. In order to specify a config ...

  3. 定时任务crontab 详解

    cron 是一个可以用来根据时间.日期.月份.星期的组合来调度对重复任务的执行的守护进程. cron 假定系统持续运行.如果当某任务被调度时系统不在运行,该任务就不会被执行. 要使用 cron 服务, ...

  4. RDL Web报表抛出ReportServerException,已取消该操作

    ::, RsBase() [ERROR] - Microsoft.Reporting.WebForms.ReportServerException: 已取消该操作. ---> System.Op ...

  5. 告别JQuery(一)

    背景 很多很多传统的Web开发者还在用着传统的jquery和ES5,大家都知道现在的前端如火如荼,但是眼花缭乱的框架和层出不穷的新概念,让很多人无从下手,本文从0开始,带你一步步由jquery操作DO ...

  6. 项目部署到centos7云端验证码出现乱码

    原因:linux系统字体和设置验证码的字体不一致 参考文献: https://www.whatled.com/post-6169.html 本次项目我使用的字体是    Arial

  7. Spring Cloud--搭建Eureka注册中心服务

    使用RestTemplate远程调用服务的弊端: Eureka注册中心: Eureka原理: 搭建Eureka服务 引pom 启动类: 启动类上要加上@EnableEurekaServer注解: 配置 ...

  8. PhpStorm 2017汉化补丁 2017.1 免费中文版

    PhpStorm 2017汉化补丁是一款可以让PhpStorm 2017.1版实现中文界面显示的汉化包工具,本站提供了PhpStorm 2017.1汉化补丁下载地址,有需要的朋友们欢迎前来下载使用. ...

  9. 准备Kendo UI 开发环境

    准备 首先你需要从 Telerik 网站下载试用版开发包,注意需要注册后才能下载. 下载后直接解压后包含下面几个文件和目录: ./examples – 示例. /js – minified 化后的 J ...

  10. optparse 模块

    一.optparse是专门用来在命令行添加选项的一个模块.支持python2.3及以上版本,从2.7版本之后,python不再更新该模块,2.7之后的版本推荐使用argparse模块. 二.optpa ...