leetcode896
- class Solution {
- public:
- bool isMonotonic(vector<int>& A) {
- if (A.size() <= )
- {
- return true;
- }
- bool GetDiff = false;//是都找到了不同元素
- bool Increace = true;//假设为增序列
- for (int i = ; i <= A.size() - ; i++)
- {
- if (GetDiff)//已经找到不相同元素
- {
- if (Increace&&A[i] > A[i + ])//应该是增序列,但遇到左>右,则表示false
- {
- return false;
- }
- if (!Increace&&A[i] < A[i + ])//应该是减序列,但遇到左<右,则表示false
- {
- return false;
- }
- }
- else
- {
- if (A[i] != A[i + ])//第一次发现不相同元素
- {
- if (A[i] < A[i + ])// 如果左<右,则后面应该都是增
- {
- Increace = true;//增序列
- }
- else//如果左>右,则后面应该都是减
- {
- Increace = false;//减序列
- }
- GetDiff = true;
- }
- }
- }
- return true;//没有出现问题,则表示true
- }
- };
leetcode896的更多相关文章
- [Swift]LeetCode896. 单调数列 | Monotonic Array
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- Leetcode896.Monotonic Array单调数列
如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的. 如果对于所有 i <= j,A[i]> = ...
- LeetCode 896. 单调数列(Monotonic Array)
896. 单调数列 896. Monotonic Array 题目描述 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i<=j,A[i]<=A[j],那么数组 A 是单调 ...
随机推荐
- LeetCode OJ:Remove Nth Node From End of List(倒序移除List中的元素)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- About GCC
GCC used to stand for the GNU C Compiler, but since the compiler supports several other languages as ...
- linux TCP Fast Open开启和测试
linux上要开启TCP Fast Open,内核版本至少为3.7.0, 且需要设置 /proc/sys/net/ipv4/tcp_fastopen 为3. 开启后,如果有连接进来,使用如下命令查看: ...
- 解决pip安装太慢的问题
经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具,但是由于国外官方pypi经常被墙,导致不可用,所以我们最好是将自己使用的pip源更换一下,这样就能解决被墙导致的装不上库的 ...
- php项目,cpu暴增问题查找
背景: 前几天通过WordPress上线一个应用(前后台部署分离,后台走内网内部使用,前台做了全站缓存对外使用). 今天访问后台应用发现开始报504,一段时间后全部504. 解决方案: 登录容器发现容 ...
- laravel 中将DB::select 得到的内容转为数组
$sql = "select count(*) as num from api_log where uid='{$this->uid}'"; $ ...
- Supervisor进程监控
安装 yum install -y python-setuptools easy_install supervisor echo_supervisord_conf > /etc/supervis ...
- sql_自连接,181,182,196,197
181. Employees Earning More Than Their Managers https://leetcode.com/problems/employees-earning-more ...
- 浅谈如何在SQL Server中生成脚本
在生成脚本过程中,有很多参数可以选择,合理的配置这些参数,可以让我们很方便的按照我们的期望生成脚本. 生成脚本的一些选项,如下图: 我这里是SQL 2005 的选项, SQL 2008 的选项跟这个稍 ...
- JQuery 提示用户名密码不为空
$(document).ready(function(){ //HTML()替换 HTML函数 //append()追加 :input = :t ...