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>& ...
随机推荐
- 【Linux高级驱动】rtc驱动开发
[1.分层思想] 1.1 rtc-dev.c //设备接口层,功能:给用户提供接口 subsys_initcall(rtc_init); , RTC_DEV_MAX, "rtc&qu ...
- 【转】Error:JAVA_HOME is not set and could not be found
如果stop-dfs.sh也报了这个错,把$HADOOP_HOME/libexec/hadoop-config.sh中的如下内容之前加上 export JAVA_HOME=/home/lqr/Tool ...
- cad巧用插件自定义填充图形
很多同志如果遇到奇葩的填充图案,怎么办,找不到合适的,自己辛苦画了一遍,想把它作为自己的自定义的图案,怎么办呢. 今天老王给你您介绍个好用的插件. 首先在命令行输入命令 ap 弹出加载对话框 打开窗 ...
- 【iCore4 双核心板_FPGA】例程一:GPIO输出实验——点亮LED
实验现象: 三色LED循环点亮. 核心源代码: module led_ctrl( input clk_25m, input rst_n, output fpga_ledr, output fpga_l ...
- CAP原理中的一致性
CAP原理指的是,这三个要素最多只能同时实现两点,不可能三者兼顾.因此在进行分布式架构设计时,必须做出取舍.而对于分布式数据系统,分区容忍性是基本要求,否则就失去了价值.因此设计分布式数据系统,就是在 ...
- 对于Python中@property的理解和使用
@property 这个我们在很多代码中都会用到,简单讲即为一个只读属性的调用 如果需要有修改权限,需要再加一个@属性名.setter 例: #!/usr/bin/env python # -*- c ...
- [React] 04 - Intro: mongoDB becomes popular
Ref: Linux平台安装MongoDB - 菜鸟教程 安装:sudo apt-get install mongodb 安装完毕产生: ls /etc/init.d/mongodb 配置:vim / ...
- jar各个版本号的意义
jar版本号的意义: Alpha: Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就 ...
- lua迭代器和泛型for浅析
(一) 首要概念要理清: 1. 在lua中,函数是一种"第一类值",他们具有特定的词法域."第一类值"表示在lua中函数与其他传统类型的值(例如数字和字符串)具 ...
- 十、K3 WISE 开发插件《SQL Profiler跟踪单据操作时产生的SQL语句》
=================================== 目录: 1.查询帐套的数据库DBID 2.配置需要跟踪数据库的DBID 3.配置跟踪参数 4.跟踪进行 5.分析跟踪语句 === ...