【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 ...
随机推荐
- [Svelte 3] Use Svelte 3 transitions to gracefully show and hide DOM elements
Most websites are quite static and adding some animations/transitions can improve the user experienc ...
- How To Set The Hostname On Ubuntu Or Debian?
$ sudo hostnamectl set-hostname your-hostname $ sudo vim /etc/hosts Open the hosts file and add the ...
- Kubernetes 学习26 基于kubernetes的Paas概述
一.概述 1.通过以往的学习应该可以了解到k8s 和以往提到的devops概念更容易落地了.比如我们说的CI,CD,CD a.CI(Continuous Integration):持续集成 b.CD( ...
- CODE FESTIVAL 2017 Final题解
传送门 \(A\) 咕咕 const int N=55; const char to[]={"AKIHABARA"}; char s[N];int n; int main(){ s ...
- php单点登录SSO(Single Sign On)的解决思路
一.什么是单点登录 解释:登录一个系统后,其它系统无需再次登录,即可进入. 二.举个例子: 你登录了淘宝,然后你进入天猫,发现你不用登录了.这时你要注意到,淘宝跟天猫可是完全不一样的域名. 你登录淘宝 ...
- Django REST framework优点?
1.提供了定义序列化器Serializer的方法,可以快速根据Django ORM 或者其他库自动序列化/反序列化2.提供了丰富的类视图\MIXIN扩展类,简化视图的编写3.丰富的定制层级:函数视图\ ...
- 【洛谷】P2568 GCD
前言 耻辱,我这个OI界的耻辱! 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对.输入格式 一个整数N输出格式答案输入输出样例 输入 4 ...
- PHP如何解决网站大流量与高并发的问题(一)
高并发的相关概念 在某个时间点,有多少个访问量 如果一个系统的日PV在千万以上,有可能是一个高并发的系统 QPS: 每秒钟请求或者查询的数量,在互联网领域,指每秒相应请求数(指HTTP请求) 吞吐量: ...
- 解决无法将java项目部署到tomcat中去
project facets java转成web项目 用Eclipse开发项目的时候,把一个Web项目导入到Eclipse里会变成了一个Java工程,将无法在Tomcat中进行部署运行. 方法: 1. ...
- 【转】分享一款颜色神器ColorSchemer Studio
原文:https://www.cnblogs.com/xyfll7/p/7569078.html ColorSchemer Studio是一款专业配色软件,网页设计或平面设计师必备工具,和ColorP ...