Easy
Valid Mountain Array — Python
Full explanation · Time O(n) · Space O(1)
# 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