【Leetcode_easy】896. Monotonic Array
problem
solution1:
class Solution {
public:
bool isMonotonic(vector<int>& A) {
int inc = true, dec = true;
for(int i=; i<A.size(); ++i)
{
inc &= (A[i]>=A[i-]);
dec &= (A[i]<=A[i-]);
}
return inc || dec;
}
};
solution2:
class Solution {
public:
bool isMonotonic(vector<int>& A) {
int inc = false, dec = false;
for(int i=; i<A.size(); ++i)
{
if(A[i]>A[i-]) inc = true;
if(A[i]<A[i-]) dec = true;
if(inc && dec) return false;
}
return true;
}
};
参考
1. Leetcode_easy_896. Monotonic Array;
2. discuss1;
3. discuss2;
完
【Leetcode_easy】896. Monotonic Array的更多相关文章
- 【LeetCode】896. Monotonic Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode_easy】905. Sort Array By Parity
problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...
- 【Leetcode_easy】922. Sort Array By Parity II
problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArray ...
- 【Leetcode_easy】665. Non-decreasing Array
problem 665. Non-decreasing Array 题意:是否能够将数组转换为非减数组. solution: 难点在于理解如何对需要修改的元素进行赋值: class Solution ...
- 【02】[].slice和Array.prototype.slice
[02][].slice和Array.prototype.slice 01,Array是一个构造函数.浏览器内置的特殊对象. 02,Array没有slice方法. 03,Array.prototy ...
- 896. Monotonic Array@python
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...
- 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)
[LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
- 【leetcode81】Product of Array Except Self
题目描述: 给定一个长度为n的整数数组Array[],输出一个等长的数组result[],这个输出数组,对应位置i是除了Array[i]之外,其他的所有元素的乘积 例如: given [1,2,3,4 ...
- 【CodeForces】896 B. Ithea Plays With Chtholly
[题目]B. Ithea Plays With Chtholly [题意]交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减.n,m>=2 ...
随机推荐
- Tensorflow细节-P190-输入文件队列
以下代码要学会几个地方 1.filename = ('data.tfrecords-%.5d-of-%.5d' % (i, num_shards)) 这个东西就是要会data.tfrecords-%. ...
- swiper插件的一些坑
最近正在做一个PC端和移动端的项目 正好用到了swiper 今天给大家拿来讲讲 swiper的官网http://www.swiper.com.cn/ 博主用的是4.0的版本 如果大家用的是3.0的版本 ...
- 阿里开源线上应用调试利器 Arthas的背后
Arthas是一个功能非常强大的诊断工具,功能点很多,例如:jvm信息.线程信息.搜索类中的方法.跟踪代码执行.观测方法的入参和返回参数等等. 作为有追求的程序员,你不仅要知道它能做什么,更要思考它是 ...
- Ubuntu安装php7.0环境
1.下载必须组件 sudo apt-get install libxml2-dev sudo apt-get install curl 参考文献:http://php.net/manual/zh/in ...
- 关灯问题II 状压DP
关灯问题II 状压DP \(n\)个灯,\(m\)个按钮,每个按钮都会对每个灯有不同影响,问最少多少次使灯熄完. \(n\le 10,m\le 100\) 状压DP的好题,体现了状压的基本套路与二进制 ...
- cgp的辣鸡比赛题解
目录 cgp的gcd 题目链接 思路 代码 cgp调戏妹子 题目链接 思路 代码 cgp的序列 题目链接 思路 代码 cgp的背包 题目链接 思路 代码 cgp的gcd 题目链接 传送门 思路 首先看 ...
- FCS省选模拟赛 Day5
传送门 Solution Code #include<bits/stdc++.h> #define ll long long #define max(a,b) ((a)>(b)?( ...
- docker run 参数含义
-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项: -d: 后台运行容器,并返回容器ID: -i: 以交互模式运行容器,通常与 -t 同时使用: ...
- @Scope("prototype")的正确用法——解决Bean的多例问题
转自: https://www.jianshu.com/p/54b0711a8ec8 1. 问题,Spring管理的某个Bean需要使用多例 在使用了Spring的web工程中,除非特殊情况,我们 ...
- 常用的maven仓库地址
maven 仓库地址: 共有的仓库http://repo1.maven.org/maven2/http://repository.jboss.com/maven2/http://repository. ...