【Leetcode_easy】941. Valid Mountain Array
problem
solution:
- class Solution {
- public:
- bool validMountainArray(vector<int>& A) {
- if(A.size()<) return false;
- int max = A[], max_id = ;
- for(int i=; i<A.size(); ++i)
- {
- if(A[i]>max)
- {
- max = A[i];
- max_id = i;
- }
- }
- if(max_id== || max_id==A.size()-) return false;//errr..
- for(int i=; i<A.size(); i++)
- {
- if(i<max_id && A[i]<=A[i-]) return false;//errr...
- if(i>max_id && A[i]>=A[i-]) return false;//errr..
- }
- return true;
- }
- };
solution2:
- class Solution {
- public:
- bool validMountainArray(vector<int>& A) {
- int i=, n=A.size()-, j=n;
- while(i<n- && A[i]<A[i+]) i++;
- while(j> && A[j-]>A[j]) j--;
- return i> && i==j && j<n;
- }
- };
参考
1. Leetcode_easy_941. Valid Mountain Array;
完
【Leetcode_easy】941. Valid Mountain Array的更多相关文章
- 【leetcode】941. Valid Mountain Array
题目如下: Given an array A of integers, return true if and only if it is a valid mountain array. Recall ...
- 【LeetCode】941. Valid Mountain Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 941. Valid Mountain Array (有效的山脉数组)
题目标签:Array 题目给了一组int array A,让我们判断它是否是 一个山脉数组. 山脉数组一定要有一个最高值,然后要同时有 山坡和下坡. 想法是,从左边开始依次比较两个数字,int[0] ...
- 【Leetcode_easy】1037. Valid Boomerang
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完
- 【Leetcode_easy】1122. Relative Sort Array
problem 1122. Relative Sort Array 参考 1. Leetcode_easy_1122. Relative Sort Array; 2. helloacm; 完
- 【Leetcode_easy】680. Valid Palindrome II
problem 680. Valid Palindrome II solution: 不理解判断函数中的节点的问题... class Solution { public: bool validPali ...
- LeetCode 941. 有效的山脉数组(Valid Mountain Array)
941. 有效的山脉数组 941. Valid Mountain Array 题目描述 给定一个整数数组 A,如果它是有效的山脉数组就返回 true,否则返回 false. 让我们回顾一下,如果 A ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- [Swift]LeetCode941. 有效的山脉数组 | Valid Mountain Array
Given an array A of integers, return true if and only if it is a valid mountain array. Recall that A ...
随机推荐
- Set的常用实现类HashSet和TreeSet
Set HashSet public static void main(String[] args) { //不可以重复 并且是无序的 //自然排序 从A-Z //eqauls从Object继 ...
- thinkpadT470P安装问题
[问题描述]: 最近在将Thinkpad E430c的ubuntu系统重装成windows 7的过程中,出现了装好win7系统后,开机自动进入boot menu界面的问题,而且不论你选择从光驱还是硬盘 ...
- django 第三天 视图
今日内容 一.url路由分发之include 项目文件夹下的urls.py文件中的url写法: from django.conf.urls import url,include from django ...
- 【Redis】Linux下Redis的安装
Redis服务安装 主要有两种方式:apt安装和编译安装. 我采用的是apt安装,系统是ubuntu18.04,Redis version 5:4.0.9-1 在 Ubuntu 系统安装 Redi 可 ...
- SaltStack 在 Windows 上的操作基础
SaltStack 在 windows上的操作基础 1.删除文件: salt '172.16.3.11' file.remove 'D:\downup\111.msu' 2.删除文件夹 salt '1 ...
- 关于Keil4 转到 Keil5以后的一些错误解决
一, 看自己选择CPU型号,根据型号再做配置 根据自己型号填写
- leetcode解题报告(32):Teemo Attacking
描述 In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poison ...
- Ural1297 最长回文子串(后缀数组+RMQ)
/* 源程序丢失QWQ. 就不粘代码了. 大体做法是把串反转然后连接. 做一遍后缀数组. 对height做一遍rmq. 然后对于每个位置的奇偶分别判断, 记下pos. 注意求的是[l+1,r]的hei ...
- 洛谷 P1230 智力大冲浪 题解
P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者 \(m\)元.先不要太高兴!因为这些钱还不一定都是你的 ...
- 机器学习实战(1)- KNN
KNN:k近邻算法-在训练样本中找到与待测样本距离相近的N个样本,并用这N个样本中所属概率最大的类别作为待测样本的类别. 算法步骤: 1.对训练中的样本数据的不同属性进行归一化处理. 2.计算待测样本 ...