941. Valid Mountain Array
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 34% Topics: Array
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def validMountainArray(self, A):
"""
:type A: List[int]
:rtype: bool
"""
i = 0
while i+1 < len(A) and A[i] < A[i+1]:
i += 1
j = len(A)-1
while j-1 >= 0 and A[j-1] > A[j]:
j -= 1
return 0 < i == j < len(A)-1
Solution from kamyu104/LeetCode-Solutions · MIT