728x90
https://leetcode.com/problems/valid-mountain-array/
class Solution:
def validMountainArray(self, arr: List[int]) -> bool:
increasing = True
change = False
if len(arr) >= 2 and arr[0] - arr[1] > 0:
increasing = False
before = arr[0]
for i in arr[1:]:
if increasing:
if i > before:
before = i
elif i < before:
before = i
increasing = False
change = True
else:
return False
else:
if i < before:
before = i
else:
return False
return True if change else False
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 1148. Article Views I (0) | 2023.08.29 |
---|---|
[Leetcode] 2356. Number of Unique Subjects Taught by Each Teacher (0) | 2023.08.28 |
[Leetcode] 1299. Replace Elements with Greatest Element on Right Side (0) | 2023.08.26 |
[Leetcode] 922. Sort Array By Parity II (0) | 2023.08.26 |
[Leetcode] 905. Sort Array By Parity (0) | 2023.08.26 |