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.
Note:
1 <= A.length <= 50000
-100000 <= A[i] <= 100000
class Solution(object):
def isMonotonic(self, A):
if (len(A) == 1):
return True target_list = []
for i in range(len(A)-1):
target_list.append(A[i+1]-A[i]) target_list_stored = sorted(target_list) for j in range(len(target_list_stored)):
if target_list_stored[0] <= 0 and target_list_stored[-1] <= 0:
return True
elif target_list_stored[0] >= 0 and target_list_stored[-1] >= 0:
return True
else :
return False
896. Monotonic Array的更多相关文章
- 896. Monotonic Array@python
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- 【Leetcode_easy】896. Monotonic Array
problem 896. Monotonic Array solution1: class Solution { public: bool isMonotonic(vector<int>& ...
- [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 解题报告
题目要求 An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is ...
- [LeetCode&Python] Problem 896. Monotonic Array
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- 896. Monotonic Array单调数组
[抄题]: An array is monotonic if it is either monotone increasing or monotone decreasing. An array A i ...
- LeetCode 896. Monotonic Array
原题链接在这里:https://leetcode.com/problems/monotonic-array/ 题目: An array is monotonic if it is either mon ...
- 【LeetCode】896. Monotonic Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 896. 单调数列(Monotonic Array)
896. 单调数列 896. Monotonic Array 题目描述 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i<=j,A[i]<=A[j],那么数组 A 是单调 ...
随机推荐
- Js 数组对象排序
1.定义函数 /** * 数组对象排序函数 * @param {any} name 排序字段 * @param {any} order 升.降(这里事true.false记得处理下) */ var b ...
- python进阶12 Redis
python进阶12 Redis 一.概念 #redis是一种nosql(not only sql)数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,还提 ...
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he we ...
- poj1185-炮兵阵地(状态压缩dp)
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25647 Accepted: 9892 Description ...
- 熔断 降级(polly)
熔断 降级(polly) https://www.cnblogs.com/szlblog/p/9300845.html1.熔断降级的概念: 熔断:我这里有一根长度一米的钢铁,钢铁的熔点1000度(假设 ...
- github 新建一个分支
我能说今天在github上新建分支的时候懵逼了半天吗..为了下次不再懵逼,还是在这里记录一下吧.. 进入你的项目---code---Branch----点击那个倒三角-----你会发现一个输入框(这是 ...
- Spark Mllib里如何提取每个字段并转换为***类型(图文详解)
不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第17章 决策树多元分类UCI Covertype数据集
- gulp管理angular2项目 配置文件
目录结构: projectName |_ src |_ app |_ index.html |_ main.ts |_ systemjs.config.js |_ gulpfile.js |_ pac ...
- JAVA基础之基本类型包装类、System类、Math类、Arrays类及大数据运算
个人理解: 为了方便运算及调用一些方法,我们需要将基本类型的数值转换为对象:不过转换的时候需要特别注意好它们的类型到底是什么,需要调用方法的类名是哪个!特别注意是Byte常量池的相关问题(==):gc ...
- 有关在python中使用Redis(一)
python作为一种处理数据的脚本语言本身有许多方法函数供大家使用,有时候为了提升数据处理速度(如海量数据的访问或者海量数据的读取),涉及分布式管理架构,可能需要用到Redis,Redis是一个开源的 ...