题目要求

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.

题目分析及思路

定义了一个monotonic数组,要求它要么是单调递增(对所有索引i <= j,对应元素A[i] <= A[j])要么是单调递减(对所有索引i <= j,对应元素A[i] >= A[j])。现在需要判断给定数组是否是monotonic。可以将给定数组与正序排好的数组和逆序排好的数组进行比较,若满足其中一项,则返回True。

python代码

class Solution:

def isMonotonic(self, A: List[int]) -> bool:

return A == sorted(A) or A == sorted(A, reverse=True)

LeetCode 896 Monotonic Array 解题报告的更多相关文章

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

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

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

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

  3. LeetCode 896. Monotonic Array

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

  4. 896. Monotonic Array@python

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

  5. 【LeetCode】697. Degree of an Array 解题报告

    [LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...

  6. 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)

    [LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...

  7. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  8. 【LeetCode】Permutations II 解题报告

    [题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...

  9. 【Leetcode_easy】896. Monotonic Array

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

随机推荐

  1. SDL获得屏幕属性及实现分析

    [时间:2017-05] [状态:Open] [关键词:sdl2,屏幕分辨率,显示区域,多媒体渲染,窗口,sdl2源码分析] 0 引言 本文的主要目标在于使用SDL2获得屏幕相关的属性,比如分辨率.屏 ...

  2. Android 浮动窗口进阶——画中画,浮动视频(附Demo)

    今天继续上一篇Android顶层窗口.浮动窗口的进阶应用.上一篇主要讲解了WindowManager服务和如何使用WindowManager编写一个顶层窗口.今天主要是讲讲如何在顶层窗口里面播放视频, ...

  3. linux 常用命令1【转】

    1.1. 关机 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours:minutes & 按预定 ...

  4. Nginx 1.9+PHP5.6 环境搭建

    PHP5. 下载安装包 #wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz #tar -zxf php-​ 安装php依赖的包​​ #yum inst ...

  5. not in 的优化

    //---------------------- 建表1 ---------------------- create table TESTTABLE( id1 VARCHAR2(12), name V ...

  6. python 迭代器模式

    迭代器模式 迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常用的设计模式.这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示. 迭代器模式属于行 ...

  7. Keepalived 配置高可用集群

    一.Keepalived 简介 (1) Keepalived 能实现高可用也能实现负载均衡,Keepalived 是通过 VRRP 协议 ( Virtual Router Redundancy Pro ...

  8. python单引号(')、双引号(")、三引号(''',""")

    python对字符串的表示方法比c更有灵活性,但是也更难理解. 为了在平时使用.看代码过程中对着单引号(').双引号(").三引号(''',""")不混淆,知道 ...

  9. 官方文档:Office VBA 参考

    https://docs.microsoft.com/zh-CN/office/vba/api/overview/    Office VBA 参考 https://docs.microsoft.co ...

  10. 开源库RxJava、ButterKnife

    1. 简介 RxJava "RxJava is a Java VM implementation of Reactive Extensions: a library for composin ...