题目要求

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. 【Java】加载驱动方法

    1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2. DriverManager.register ...

  2. debian/deepin 15.3 15.4安装jdk 1.7 (或jdk 7),配置默认环境

    一.前言 Deepin 15.3是基于Debian开发的,安装jdk 1.7有所不同,默认是openjdk-8-jdk,而我们玩一些编译需要的是jdk 7. 所以本文给出安装JDK 7的教程. Dee ...

  3. jq ajax post body raw传json

    $.ajax( { url: '', 'data': JSON.stringify({ }), 'type': 'POST', 'processData': false, 'contentType': ...

  4. postman中 form-data、x-www-form-urlencoded、raw、binary的区别--转

    原文地址:http://blog.csdn.net/ye1992/article/details/49998511 1.form-data:  就是http请求中的multipart/form-dat ...

  5. Mysql 查看连接数,状态 最大并发数 && 怎么设置才合理

    show status like '%max_connections%'; ##mysql最大连接数 set global max_connections=1000 ##重新设置 show varia ...

  6. Map字符串类型去掉空格处理

     Iterator it = data.keySet().iterator(); for (; it.hasNext();) { if( data.get(key) instanceof  Strin ...

  7. 【01月22日】A股滚动市盈率PE最低排名

    深康佳A(SZ000016) - 滚动市盈率PE:1.55 - 滚动市净率PB:1.03 - 滚动年化股息收益率:4.71% - - - 深康佳A(SZ000016)的历史市盈率走势图 华菱钢铁(SZ ...

  8. .net core 开发接口前端调用时提示错误 405

    解决方法: 在StartUp.cs文件中Configure(IApplicationBuilder app, IHostingEnvironment env)方法中添加如下代码: //跨域 app.U ...

  9. JavaScript隐藏的坑一,隐式调用toString

    最近在重新学习JavaScript,看动态原型对象的时候,打印了两个用同一个构造函数生成的对象,但是打印结果却不一样,请看代码: var box1=new Box(); console.log(box ...

  10. Unity ---WidgetsUI CreateTileView Demo

    以下教程基于:WidgetsUI 第三方扩展包 WidgtsUI 官网文档地址:https://ilih.ru/unity-assets/UIWidgets/docs/ 1.创建一个空GameObje ...