题目如下:

Given an array A of integers, return true if and only if it is a valid mountain array.

Recall that A is a mountain array if and only if:

  • A.length >= 3
  • There exists some i with 0 < i < A.length - 1 such that:
    • A[0] < A[1] < ... A[i-1] < A[i]
    • A[i] > A[i+1] > ... > A[B.length - 1]

Example 1:

Input: [2,1]
Output: false

Example 2:

Input: [3,5,5]
Output: false

Example 3:

Input: [0,3,2,1]
Output: true

Note:

  1. 0 <= A.length <= 10000
  2. 0 <= A[i] <= 10000 

解题思路:非常简单的题目,没啥说的。

代码如下:

class Solution(object):
def validMountainArray(self, A):
"""
:type A: List[int]
:rtype: bool
"""
if len(A) < 3:
return False
last = None
directon = None
for i in A:
if last == None:
last = i
elif directon == None and last < i:
directon = 0
last = i
elif directon == None and last > i:
return False
elif directon == 0 and last < i:
last = i
elif directon == 0 and last > i:
directon = 1
last = i
elif directon == 1 and last > i:
last = i
else:
return False
return directon == 1

【leetcode】941. Valid Mountain Array的更多相关文章

  1. 【LeetCode】941. Valid Mountain Array 解题报告(Python)

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

  2. 【Leetcode_easy】941. Valid Mountain Array

    problem 941. Valid Mountain Array solution: class Solution { public: bool validMountainArray(vector& ...

  3. 【LeetCode】593. Valid Square 解题报告(Python)

    [LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...

  4. 【LeetCode】36. Valid Sudoku 解题报告(Python)

    [LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...

  5. 【LeetCode】678. Valid Parenthesis String 解题报告(Python)

    [LeetCode]678. Valid Parenthesis String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...

  6. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

  7. 【LeetCode】数组-6(561)-Array Partition I(比较抽象的题目)

    题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs o ...

  8. 【LeetCode】680. Valid Palindrome II

    Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...

  9. 【LeetCode】845. Longest Mountain in Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双数组 参考资料 日期 题目地址:https://l ...

随机推荐

  1. POJ 3348 Cows (凸包模板+凸包面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  2. Git 中关于一次完整的提交的命令

    1.创建仓库(git init .git clone URL) 有两种新建 Git 项目仓库的方法.第一种是在本地通过初始化来创建新的 Git 仓库.第二种是从已有的 Git 远程仓库中克隆出一个仓库 ...

  3. 自定义combiner实现文件倒排索引

    package com.zuoyan.hadoop; import java.io.IOException; import org.apache.hadoop.conf.Configuration; ...

  4. 查看SQL Server被锁的表以及如何解锁【转】

    锁定数据库的一个表的区别  SELECT * FROM table WITH (HOLDLOCK) 其他事务可以读取表,但不能更新删除  SELECT * FROM table WITH (TABLO ...

  5. window安装consul

    安装consul 下载包: https://www.consul.io/ 解压 consul_1..2_windows_amd64.zip 复制 consul.exe 到 d:\soft\consul ...

  6. [CSP-S模拟测试]:marshland(最大费用可行流)

    题目描述 前方有一片沼泽地.方便地,我们用一个$n\times n$的网格图来描述它,每一个格子代表着沼泽地的一小片区域.其中$(1,1)$代表网格图的左上角,$(n,n)$代表网格图的右下角.若用$ ...

  7. python的os.path.join()

    在python中,os.path.join()是用来拼接目录路径得.同类型得还有join(),os.path.spilt(),spilt()三个函数.1,os.path.join(),将join()里 ...

  8. MySQL-初始化和自动更新TIMESTAMP和DATETIME

    https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html 例,添加自动更新的保存最后一次修改该条记录的时间戳的字段: ...

  9. Linux中zip压缩和解压缩命令

    主要参数 -c:将解压缩的结果-l:显示压缩文件内所包含的文件-p:与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换-t:检查压缩文件是否正确-u:与-f参数类似,但是除了更新现有的 ...

  10. 如何使用Charles对手机进行抓包

    步骤:(如下为ios步骤,安卓类似) 1)Mac安装Charles,保证手机与电脑在同一wifi(若没有WiFi时,Mac.MacBook,etc 自带热点功能) 2)在手机当前连接的wifi设置里配 ...