mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
Update and rename array-check_mountain.py to check_mountain.py
This commit is contained in:
parent
37a25d4423
commit
5c0e0228e6
@ -4,8 +4,7 @@
|
||||
|
||||
'''
|
||||
Given an array of integers arr, return true if and only if it is a valid mountain array.
|
||||
|
||||
Recall that arr is a mountain array if and only if:
|
||||
An array is a moutain array if and only if:
|
||||
|
||||
arr.length >= 3
|
||||
There exists some i with 0 < i < arr.length - 1 such that:
|
||||
@ -20,24 +19,18 @@ def valid_mountain_array(arr: list[int]) -> bool:
|
||||
for i, n in enumerate(arr[1:]):
|
||||
|
||||
if n > last_number:
|
||||
|
||||
if mountain_up == False:
|
||||
return False
|
||||
|
||||
elif n < last_number:
|
||||
|
||||
if i == 0:
|
||||
return False
|
||||
mountain_up = False
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
last_number = n
|
||||
|
||||
return not mountain_up
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arr = [0,3,2,1]
|
||||
print(valid_mountain_array(arr))
|
Loading…
x
Reference in New Issue
Block a user