problem

896. Monotonic Array

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的更多相关文章

  1. 【LeetCode】896. Monotonic Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【Leetcode_easy】905. Sort Array By Parity

    problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...

  3. 【Leetcode_easy】922. Sort Array By Parity II

    problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArray ...

  4. 【Leetcode_easy】665. Non-decreasing Array

    problem 665. Non-decreasing Array 题意:是否能够将数组转换为非减数组. solution: 难点在于理解如何对需要修改的元素进行赋值: class Solution ...

  5. 【02】[].slice和Array.prototype.slice

    [02][].slice和Array.prototype.slice 01,Array是一个构造函数.浏览器内置的特殊对象.   02,Array没有slice方法. 03,Array.prototy ...

  6. 896. Monotonic Array@python

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  7. 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)

    [LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...

  8. 【leetcode81】Product of Array Except Self

    题目描述: 给定一个长度为n的整数数组Array[],输出一个等长的数组result[],这个输出数组,对应位置i是除了Array[i]之外,其他的所有元素的乘积 例如: given [1,2,3,4 ...

  9. 【CodeForces】896 B. Ithea Plays With Chtholly

    [题目]B. Ithea Plays With Chtholly [题意]交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减.n,m>=2 ...

随机推荐

  1. Windows异常相关数据结构

    当一个异常发生时,操作系统要向引起异常的线程的栈里压入三个结构,这三个结构是:E X C E P T I O N _ R E C O R D结构.C O N T E X T结构和E X C E P T ...

  2. 通过map文件找程序崩溃的代码行

    一,配置vs 二,程序崩溃界面 // ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include &l ...

  3. C位运算符的使用

    #include <stdio.h> int main(void) { //位运算符 & | ^ ~ printf("8|2=%d\n",8|2);// 10 ...

  4. AtCoder Grand Contest 017题解

    传送门 \(A\) 直接转移就是了 typedef long long ll; const int N=55; ll f[N][2];int a[N],n,p; int main(){ scanf(& ...

  5. package.json 版本号解释

    经常看到package.json中的各种版本号记录 比如 ~ ^ 等.其实是有个规范的.其遵循 semver. 具体的网站为:  http://semver.org/lang/zh-CN/

  6. ICEM——倒角的处理

    原视频下载地址: https://pan.baidu.com/s/1miHMOuk 密码: knc4

  7. js中的那些遍历

    说到遍历,首先想到的是数组的遍历,方法不要太多,比如 for, forEach,map,filter,every,some等 下面来看下,用法 首先 定义一个数组: 1. for循环,需要知道数组的长 ...

  8. JS中注入eval, Function等系统函数截获动态代码

    正文 现在很多网站都上了各种前端反爬手段,无论手段如何,最重要的是要把包含反爬手段的前端javascript代码加密隐藏起来,然后在运行时实时解密动态执行. 动态执行js代码无非两种方法,即eval和 ...

  9. 基于Redis的分布式锁到底安全吗(上)?

    基于Redis的分布式锁到底安全吗(上)?  2017-02-11 网上有关Redis分布式锁的文章可谓多如牛毛了,不信的话你可以拿关键词“Redis 分布式锁”随便到哪个搜索引擎上去搜索一下就知道了 ...

  10. Open vSwitch系列实验(三):Open vSwitch的VxLAN隧道网络实验

    1 实验目的 该实验通过Open vSwitch构建Overlay的VxLAN网络,更直观的展现VxLAN的优势.在实验过程中,可以了解如何建立VxLAN隧道并进行配置,并实现相同网段和不同网段之间的 ...