mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -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.
|
Given an array of integers arr, return true if and only if it is a valid mountain array.
|
||||||
|
An array is a moutain array if and only if:
|
||||||
Recall that arr is a mountain array if and only if:
|
|
||||||
|
|
||||||
arr.length >= 3
|
arr.length >= 3
|
||||||
There exists some i with 0 < i < arr.length - 1 such that:
|
There exists some i with 0 < i < arr.length - 1 such that:
|
||||||
@ -20,12 +19,10 @@ def valid_mountain_array(arr: list[int]) -> bool:
|
|||||||
for i, n in enumerate(arr[1:]):
|
for i, n in enumerate(arr[1:]):
|
||||||
|
|
||||||
if n > last_number:
|
if n > last_number:
|
||||||
|
|
||||||
if mountain_up == False:
|
if mountain_up == False:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif n < last_number:
|
elif n < last_number:
|
||||||
|
|
||||||
if i == 0:
|
if i == 0:
|
||||||
return False
|
return False
|
||||||
mountain_up = False
|
mountain_up = False
|
||||||
@ -37,7 +34,3 @@ def valid_mountain_array(arr: list[int]) -> bool:
|
|||||||
|
|
||||||
return not mountain_up
|
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