LeetCode 896 Monotonic Array 解题报告
题目要求
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all i <= j, A[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 解题报告的更多相关文章
- 【LeetCode】896. Monotonic Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] 896. Monotonic Array 单调数组
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- LeetCode 896. Monotonic Array
原题链接在这里:https://leetcode.com/problems/monotonic-array/ 题目: An array is monotonic if it is either mon ...
- 896. Monotonic Array@python
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- 【LeetCode】697. Degree of an Array 解题报告
[LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...
- 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)
[LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【Leetcode_easy】896. Monotonic Array
problem 896. Monotonic Array solution1: class Solution { public: bool isMonotonic(vector<int>& ...
随机推荐
- 微信mac版的bug 直接显示了消息原始数据
<msg> <voicemsg endflag="1" cancelflag="0" forwardflag="0" vo ...
- 【原】使用Tkinter绘制GUI并结合Matplotlib实现交互式绘图
在数据分析的过程中,往往需要对所建立的模型进行可视化,并调整其中的某些参数. 通常情况下,在Python中可以通过Matplotlib来进行绘制图像.然而该绘制过程是静态的,也就是每次调整完参数需要重 ...
- 嵌入式开发之精确延时---多线程延时阻塞精度asm("nop") nanosleep usleep sleep select
http://blog.csdn.net/lile777/article/details/45503087
- H3C ER6300 + 两台 H3C S5120 组网举例
组网需求: 1.H3C ER6300 作出口路由.防火墙及Qos限速等功能(ER6300 配置LAN口 192.168.30.254默认网关) 2.H3C S5120 两台配置相同VLAN10 VLA ...
- 图解CentOS系统启动流程
当我们按下开机键后,系统背后的秘密我们是否了解呢?这里,我带大家探索一下linux系统开机背后的秘密. 1.加电自检 主板在接通电源后,系统首先由POST程序来对内部各个设备进行检查,自检中如 ...
- SpringSecurity兑现多登录成功页面和登录成功返回被拦截界面
SpringSecurity实现多登录成功页面和登录成功返回被拦截界面 使用SrpingSceurity作为认证和授权的安全框架可以省下很多基础工作. 具体可以参考SpringSecurity,这里不 ...
- react中实现搜索结果中关键词高亮显示
网上看到很多js实现的关键词高亮显示,方法都是一个道理,先获取要替换的文字区域,然后在用正则匹配到关键词,并进行替换. react中实现起来似乎更简单一些. 我这里的需求是通过搜索框搜索出新闻列表,在 ...
- SpringBoot------Servlet3.0的注解自定义原生Listener监听器
前言 常用监听器: //contextListener可以监听数据库的连接,第三方组件的交互,还有静态文件加载等等 servletContextListener HttpSessionListener ...
- [Cubieboard] 镜像资源汇总
Linaro Server 14.04 (SDCard) 下载:cb2-lubuntu-server-tsd-tfcard-v2.0.img.gz 内核:GNU/Linux 3.4.79 armv7l ...
- cocos2d-x游戏引擎核心(3.x)----事件分发机制之事件从(android,ios,desktop)系统传到cocos2dx的过程浅析
(一) Android平台下: cocos2dx 版本3.2,先导入一个android工程,然后看下AndroidManifest.xml <application android:label= ...