Created
May 18, 2013 04:41
-
-
Save st0le/5603269 to your computer and use it in GitHub Desktop.
max_diff_linear
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 max_diff_linear(L): | |
min_index = 0 | |
max_diff = start = end = 0 | |
for i in xrange(len(L)): | |
if L[i] < L[min_index]: min_index = i | |
if max_diff < L[i] - L[min_index]: | |
max_diff = L[i] - L[min_index] | |
start,end = min_index,i | |
return max_diff,start,end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment