896.Montonic Array - LeetCode
Question


Solution
题目大意:
类似于数学中的减函数,增函数和物理中的加速度为正或为负
思路:
先比较前两个是大于0还是小于0,如果等于0就比较第2,3两个,依次类推,得到这个是递增数组还递减数组后再遍历接下来的数就好办了
Java实现:
public boolean isMonotonic(int[] A) {
if (A.length == 1) return true;
int compFlag = 0;
int i = 1;
while (compFlag == 0 && i < A.length) {
compFlag = A[i] - A[i - 1];
i++;
}
while (compFlag > 0 && i < A.length) {
if (A[i] - A[i - 1] < 0) return false;
i++;
}
while (compFlag < 0 && i < A.length) {
if (A[i] - A[i - 1] > 0) return false;
i++;
}
return true;
}
896.Montonic Array - LeetCode的更多相关文章
- 896. Monotonic Array@python
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- Find Minimum in Rotated Sorted Array leetcode
原题链接 直接贴代码,这道题是 search in rotated sorted array leetcode 的前面部分! class Solution { public: int findMin( ...
- Find First and Last Position of Element in Sorted Array - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Find First and Last Position of Element in Sorted Array - LeetCode 注意点 nums可能 ...
- 【Leetcode_easy】896. Monotonic Array
problem 896. Monotonic Array solution1: class Solution { public: bool isMonotonic(vector<int>& ...
- 697. Degree of an Array - LeetCode
697. Degree of an Array - LeetCode Question 697. Degree of an Array - LeetCode Solution 理解两个概念: 数组的度 ...
- [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 ...
- 【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 ...
随机推荐
- ESD@TVS选型
一.工作原理 ESD ESD静电保护元件,又称静电抑制二极管.ESD是多个TVS晶粒或二极管采用不同的布局做成具有特定功能的多路或单路ESD保护器件,主要应用于各类通信接口静电保护,如USB.HDMI ...
- 基于vue2.0的在线电影APP,
基于vue2.0构建的在线电影网[film],webpack + vue + vuex + vue-loader + keepAlive + muse-ui + cordova 全家桶,cordova ...
- css样式权重优先级,css样式优先级
原文:http://www.bkjia.com/Javascri... 样式选择器权重优先级: important > 内嵌样式 > ID > 类 > 标签 | 伪类 | 属性 ...
- 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
-webkit-box 的用法 通常,在移动端要实现水平方向平分宽度的布局,会使用 -webkit-box 来布局.它的使用方法是: <div class='parent'> <di ...
- ES6-11学习笔记--Reflect
Reflect 映射 将Object属于语言内部的方法放到Reflect上 修改某些Object方法的返回结果,让其变得更合理 让Object操作编程函数行为 Reflect对象的方法与Proxy对象 ...
- Android bluetoothAdapter.startDiscovery()无法搜索设备问题解决办法
Android6.0以上要定位权限,要手动把手机软件的定位权限打开,又被坑了好长时间
- jboss修改内存
在修改配置文件,在 <JBOSS_HOME> /bin/stadalone.conf中 找到并修改 如图
- 基于node实现一个简单的脚手架工具(node控制台交互项目)
实现控制台输入输出 实现文件读写操作 全原生实现一个简单的脚手架工具 实现vue-cli2源码 一.实现控制台输入输出 关于控制台的输入输出依然是基于node进程管理对象process,在proces ...
- SpringMVC快速使用——基于XML配置和Servlet3.0
SpringMVC快速使用--基于XML配置和Servlet3.0 1.官方文档 https://docs.spring.io/spring-framework/docs/5.2.8.RELEASE/ ...
- Postman中文版客户端
"新冷战"蔓延到生产力工具 前端时间,著名 UI 设计软件 Figma 宣布制裁大疆! 这不仅让中国的互联网从业者纷纷一头冷汗:今天是 Figma,明天会是什么?今天是大疆,明天会 ...