题目要求

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. 【Android】Android布局文件的一些属性值

    第一类:属性值 true或者 false   android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 androi ...

  2. oracle 11g rac asm磁盘组增加硬盘

    要增加磁盘的磁盘组为:DATA 要增加的磁盘为: /dev/sde1 在第一个节点上:[root@rac1 ~]# fdisk /dev/sdeDevice contains neither a va ...

  3. java转换日期格式为 RFC1123

    import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util. ...

  4. rsync安装及部署

    一.服务器端1.yum -y install rsync xinetd 2.vi /etc/xinetd.d/rsync 将yes 修改为no IPV6修改为IPV4 3.vi /etc/rsyncd ...

  5. bootstrap 3.0 LESS源代码浅析(二)

    border-radius是最常见的CSS3属性,但你知道他多少东西呢? 比如: border-radius:2em; 相当于什么? border-top-left-radius:2em; borde ...

  6. Angular4学习笔记(五)- 数据绑定、响应式编程和管道

    概念 Angular中的数据绑定指的是同一组件中控制器文件(.ts)与视图文件(.html)之间的数据传递. 分类 流向 单向绑定 它的意思是要么是ts文件为html文件赋值,要么相反. ts-> ...

  7. [React] 11 - Redux: redux

    Ref: Redux中文文档 Ref: React 讀書會 - B團 - Level 19 Redux 深入淺出 Ref: React+Redux 分享會 Ruan Yifeng, Redux 架构: ...

  8. ASP.NET MVC 4 (十二) Web API

    Web API属于ASP.NET核心平台的一部分,它利用MVC框架的底层功能方便我们快速的开发部署WEB服务.我们可以在常规MVC应用通过添加API控制器来创建web api服务,普通MVC应用程序控 ...

  9. Fiddler 简介

    Fiddler 简介: (1) Fiddler 是一个抓包工具,主要用来对 HTTP 请求进行分析,浏览器按 F12 也可以进行抓包,但是比较轻量,不支持一些复杂的抓包:(2) WireShark 工 ...

  10. 如何获取控件id,包名,类名