【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 ...
随机推荐
- JavaWeb(一):Java技术概览
一.Java技术体系 在早期,Java被称为Java开发工具包或JDK,是一门与平台(由一组 必需的API组成)紧密耦合的语言. 从1998年底的1.2版本开始,Java技术栈被分割为下面关键部分: ...
- dubbo-go 的开发、设计与功能介绍
dubbo-go 的前世今生 dubbo-go 是目前 Dubbo 多语言生态最火热的项目.dubbo-go 最早的版本应该要追溯到 2016 年,由社区于雨同学编写 dubbo-go 的初版.当时很 ...
- Linux二进制程序安装使用
下载好的二进制,压缩包解压,或者直接是二进制. 放到想要的目录 在 /etc/environment 双引号前面添加程序路径 以:开头,\结尾可以换行 接下来修改sudo ,不然sudo会找不到 以下 ...
- 戴尔DELL P2419H显示器连接笔记本之后,笔记本的耳机不工作了
去control panel,找到sound 在playback的tab上,重新设置default
- 测开之路五十一:代码实现MongoDB增删改查
初始化时连接.析构时断开连接 from pymongo import MongoClient class Mogo(object): def __init__(self, host='127.0.0. ...
- PromQL
PromQL (Prometheus Query Language) 是 Prometheus 自己开发的数据查询 DSL 语言,语言表现力非常丰富,内置函数很多,在日常数据可视化以及rule 告警中 ...
- upc组队赛16 Melody【签到水】
Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...
- selenium快捷键操作
常用的键盘操作 send_keys(Keys.BACK_SPACE) 删除键(BackSpace) send_keys(Keys.SPACE) 空格键(Space) send_keys(Keys.TA ...
- pandas认识
import numpy as np import pandas as pd # pandas 主要是用来进行数据处理的库, # 里面不仅包含了数据处理.甚至还有 统计分析.相关计算,其内部封装了nu ...
- hdfs 创建一个新用户
需要给第三方提供hdfs用户,和上传文件的权限 1.需要先在linux 上创建一个普通用户: hn,并修改密码 sudo -u hdfs hadoop fs -mkdir /user/用户名 sudo ...