题目如下:

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. Oracle中表连接的运行原理

    Oracle优化器会自动选择以下三种方式的一种运行表连接,但在数据环境上配合强化选择合适的方式或强制使用某种方式是SQL优化的需要:      NESTED LOOP 对于被连接的数据子集较小的情况, ...

  2. Git 如何删除分支

  3. Tomcat 中get请求中含有中文字符时乱码的处理

    Tomcat 中get请求中含有中文字符时乱码的处理

  4. 基于Socket和OpenCV的实时视频传输

    https://blog.csdn.net/pengz0807/article/details/52204475

  5. Delphi读取和写入utf-8编码格式的文件

    读取UTF-8格式的文件内容 function LoadUTF8File(AFileName: string): string; var ffileStream:TFileStream; fAnsiB ...

  6. python使用开源图片识别第三方库tesseract

    详细安装博客:https://blog.csdn.net/luanyongli/article/details/81385284 第一步tesseract-ocr的安装如果不会请参照:https:// ...

  7. sql优化工具SQLAdvisor的安装

    原文地址:https://www.cnblogs.com/beliveli/articles/6541936.html 本机安装包路径: D:\share\src\linux-mysql\sqlAdv ...

  8. [杂题]:C/c(二分答案)

    题目传送门(内部题54) 输入格式 第一行一个整数表示$n$.第二行$n$个整数表示初始序列.(这行原题没有,是我加的)接下来$2n$行每行两个整数,分别表示$X_i,Y_i$.数据保证至少存在一种方 ...

  9. Java中static修饰类的问题

    Java中static修饰类的问题 众所周知,Java中static关键字可以修饰方法与变量: 修饰变量的时候,这个变量属于类变量,可以直接通过类名.变量名来引用. 修饰方法的时候可以直接通过类名.方 ...

  10. nvm常用命令

    安装nvm:curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash 查看当前nvm版本: ...