Skip to content

Commit 62b98dd

Browse files
authored
Create valid-mountain-array.py
1 parent 0a8fae7 commit 62b98dd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/valid-mountain-array.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def validMountainArray(self, A):
6+
"""
7+
:type A: List[int]
8+
:rtype: bool
9+
"""
10+
i = 0
11+
while i+1 < len(A) and A[i] < A[i+1]:
12+
i += 1
13+
j = len(A)-1
14+
while j-1 >= 0 and A[j-1] > A[j]:
15+
j -= 1
16+
return 0 < i == j < len(A)-1

0 commit comments

Comments
 (0)