【leetcode】941. Valid Mountain Array
题目如下:
Given an array
Aof integers, returntrueif 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
iwith0 < i < A.length - 1such 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: falseExample 2:
Input: [3,5,5]
Output: falseExample 3:
Input: [0,3,2,1]
Output: trueNote:
0 <= A.length <= 100000 <= 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的更多相关文章
- 【LeetCode】941. Valid Mountain Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode_easy】941. Valid Mountain Array
problem 941. Valid Mountain Array solution: class Solution { public: bool validMountainArray(vector& ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- 【LeetCode】36. Valid Sudoku 解题报告(Python)
[LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...
- 【LeetCode】678. Valid Parenthesis String 解题报告(Python)
[LeetCode]678. Valid Parenthesis String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...
- 【LeetCode】65. Valid Number
Difficulty: Hard More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...
- 【LeetCode】数组-6(561)-Array Partition I(比较抽象的题目)
题目描述:两句话发人深思啊.... Given an array of 2n integers, your task is to group these integers into n pairs o ...
- 【LeetCode】680. Valid Palindrome II
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...
- 【LeetCode】845. Longest Mountain in Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双数组 参考资料 日期 题目地址:https://l ...
随机推荐
- 【leetcode】572. Subtree of Another Tree
题目如下: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure ...
- DataInput接口说明及其实现类
一. DataInput接口 DataInput接口提供了一系列的方法从二进制流中读取字节,并将读取出来的字节转换成任意的java基本类型,包括转换成UTF-8类型的字符串. 该接口中主要方法介绍如下 ...
- php strtolower()函数 语法
php strtolower()函数 语法 作用:把所有字符转换为小写.大理石量具 语法:strtolower(string) 参数: 参数 描述 string 必须,规定要转换的字符串 说明:str ...
- LOJ 2555 「CTSC2018」混合果汁——主席树
题目:https://loj.ac/problem/2555 二分答案,在可以选的果汁中,从价格最小的开始选. 按价格排序,每次可以选的就是一个前缀.对序列建主席树,以价格为角标,维护体积和.体积*价 ...
- idea下web工程的编译和输出设置
公司的一个项目,别人用的eclipse,我这边用IDEA,路径上出了点问题,现在大概有点头绪了,记录下来. 打开project structure后,看到如下设置,最重要的是Modules和Artif ...
- Python中生成器和yield语句的用法详解
Python中生成器和yield语句的用法详解 在开始课程之前,我要求学生们填写一份调查表,这个调查表反映了它们对Python中一些概念的理解情况.一些话题("if/else控制流" ...
- bootstrap基础模板页面,详细注释
<!--html5 骨架--> <!DOCTYPE html> <!--语言是中文简体--> <html lang="zh-cn"&g ...
- python2.7.13标准库文件目录操作与文件操作
标准库的中文参考文档: http://python.usyiyi.cn/translate/python_278/library/index.html 官方标准库文档:https://docs.pyt ...
- HP Loadrunner 12.53的下载与安装
HP Loadrunner 12.53的下载与安装 HP Loadrunner 12.53的下载:http://pan.baidu.com/s/1c23axHm HP Loadrunner 12. ...
- 怎样使用haskell编写应用程序
参考:http://stackoverflow.com/a/9153617 http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_prog ...