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>& ...
随机推荐
- oracle数据泵笔记
1.创建目录 查询已有目录:select * from dba_directories 创建并授权: CREATE DIRECTORY dump_dir AS '/tmp/' grant read,w ...
- 【iCore4 双核心板_ARM】例程二十一:LWIP_TCP_SERVER实验——以太网数据传输
实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); adc.initialize(); delay.in ...
- MSM8953 audio dts 代码跟踪
跟一下msm8953音频的dts. msm8953-audio-mtp.dtsi &int_codec { status = "okay"; qcom,model = &q ...
- Scala学习笔记(三):==,eq与equals的区别
== Scala中==与java中不同,它是比较值是否相等的,无论比较对象是否是相同类型 List(1, 2, 3) == List(1, 2, 3) //true 1==1.0//true equa ...
- 【QT】无需写connect代码关联信号和槽函数
对于一些简单的事件判别,如点击按钮. 无需写代码关联信号和槽函数. connect(ui->Btnshowhello,SIGNAL(clicked(bool)),this,SLOT(Btnsho ...
- [Tensorflow] Object Detection API - prepare your training data
From: TensorFlow Object Detection API This chapter help you to train your own model to identify obje ...
- 采用镜像的方法安装python第三方库
转自:https://blog.csdn.net/s740556472/article/details/68557330 pip install --index https://pypi.mirror ...
- 【laravel5.6】 laravel 执行 php artisan route:cache 报错 Unable to prepare route [/] for serialization. Uses Closure.
laravel 在部署的时候.需要优化路由加载,执行命令 php artisan route:cache 报错了.如下 这个异常的错误信息,提示的已经非常明确了:大概意思就是说在闭包里边,是不能够进行 ...
- 二叉树的遍历--C#程序举例二叉树的遍历
二叉树的遍历--C#程序举例二叉树的遍历 关于二叉树的介绍笨男孩前面写过一篇博客 二叉树的简单介绍以及二叉树的存储结构 遍历方案 二叉树的遍历分为以下三种: 先序遍历:遍历顺序规则为[根左右] 中序遍 ...
- css3整理--background-size
background-size语法: /*Mozilla*/ -moz-background-size: auto || <length> || <percentage> || ...