Last active
June 23, 2017 13:51
-
-
Save DeastinY/41db15ca9c2734a087f0c4ad327151c4 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 f(a, r): | |
last = a[0] | |
for i in range(len(a)): | |
if abs(last - a[i]) > r: | |
return False | |
last = a[i] | |
return True | |
def g(a, r): | |
last, j, p = a[0], 0, [] | |
m = len(a) - 1 | |
while j < m: | |
while j < m and abs(last-a[j]) <= r: | |
j+=1 | |
j-=1 | |
p.append(a[j]) | |
last = a[j] | |
while j < m and abs(last-a[j]) <= r: | |
j+=1 | |
last=a[j] | |
return p | |
t = [0,1,2,3,6,7,9,11,14,15] | |
print(f(t,r=3)) | |
print(g(t,r=3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment