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 是单调 ...
随机推荐
- sublime配置nodejs运行调试js
node.js调试javascript的配置 1. 首先到 nodejs.org 下载 Node.js 安装包并安装.2. 打开 Sublime Text 编辑器.选择菜单 Tools --> ...
- shell编程 条件判断式----利用 case ..... esac 判断
条件判断式----利用 case ..... esac 判断 case $变量名称 in <==关键词为 case ,还有变量前有钱字号 "第一个变量内容") &l ...
- java模拟多线程
public class HTTPRequest implements Runnable { public void run() { //这里实现发送请求 } public static void ...
- Django-Rest-Framework的视图和路由
Django-Rest-Framework的视图和路由 restful framework Django-Rest-Framework的视图 APIView django中写CBV的时候继承的是V ...
- How far away(DFS+vector存图)
There are n houses in the village and some bidirectional roads connecting them. Every day peole alwa ...
- HTTP/2之旅 (翻译)
Journey to HTTP/2 HTTP/2 距离我上一次通过博客写作以来, 经过了很长的一段安静的时间. 因为一直没有足够的时间投入其中. 直到现在有了一些空闲的时间, 我想利用他们写一些HTT ...
- LCA 离线做法tarjan
tarjan(int u) { int v; for(int i=h[u];i;i=nex[i])//搜索边的 { v=to[i]; tarjan(v); marge(u,v); vis[v]=; } ...
- C# 對 List<string> 取交集、補集、超集、串聯
List<string> ls1 =new List<string> { "a", "b", "c", " ...
- hystrix 应用问题
1.问题总结, 如果项目中使用了ThreadLocal,注意hystix创建新线程时,ThreadLocal中存的是之前线程中的数据,在hystix线程中获取不到 2.问题 throwable异常参数 ...
- js监听页面的scroll事件,当移到底部时触发事件
//页面拉到底时自动加载更多 $(window).scroll(function(event){ var wScrollY = window.scrollY; // 当前滚动条位置 var wInne ...