#941

Valid Mountain Array

pupil · 500 · lc easy +27 · verified · 35% accepted · 3,133 likes · top 13%

Description

Return true if integer array arr is a valid mountain: it must have at least three elements, values must strictly increase to a peak at some index strictly between the two ends, and then strictly decrease all the way to the last element.

Example 1:

Input: arr = [2,1]
Output: false

Example 2:

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

Example 3:

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

Code

1
2
3