-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path371.py
More file actions
26 lines (21 loc) · 714 Bytes
/
371.py
File metadata and controls
26 lines (21 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution:
def validMountainArray(self, arr: List[int]) -> bool:
if len(arr) < 3:
return False
peak_idx1 = 0
for i in range(1, len(arr)):
if arr[i] > arr[i-1] and peak_idx1 >= 0:
peak_idx1 = i
elif arr[i] == arr[i-1]:
peak_idx1 = -1
if peak_idx1 <= 0:
return False
peak_idx2 = 0
for i in range(len(arr)-2, -1, -1):
if arr[i] > arr[i+1] and peak_idx2 >= 0:
peak_idx2 = i
elif arr[i] == arr[i+1]:
peak_idx2 = -1
if peak_idx2 <= 0:
return False
return peak_idx1 == peak_idx2