Created
March 20, 2018 17:35
-
-
Save KoStard/9431c8130e17b38a5e7be4f9495f57c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_rel(arr, i, i1 = -1): | |
if i!=0 or i1!=-1: | |
if i1==-1: | |
i1 = i-1 | |
if arr[i]>arr[i1]: | |
return +1 | |
elif arr[i]<=arr[i1]: | |
return -1 | |
else: | |
return 0 | |
def check_node(arr, i, c_i, rel): | |
c_rel = get_rel(arr, c_i) | |
if c_rel!=rel: | |
cc_rel = get_rel(arr, i, c_i-1) | |
return c_rel==cc_rel | |
return True | |
def task80(arr): | |
for i in range(1, len(arr)): | |
rel = get_rel(arr, i) | |
for c_i in range(i-1, 0, -1): | |
if not check_node(arr, i, c_i, rel): | |
print(False) | |
return | |
print(True) | |
return | |
""" | |
task80([5,4,3,2,1]) | |
task80([1,2,3,2]) | |
task80([5,5,4,5]) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment