diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index 1575179..545e52f 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -19,4 +19,27 @@ def local_maxima(x): Output: idx -- list of indices of the local maxima in x """ - return [] + list_of_maxima = [] + if x[0]>x[1]: + list_of_maxima.append(0) + + + for i in range(len(x) -2): + if x[i+1] >= x[i] and x[i+1] >= x[i+2]: + list_of_maxima.append(i+1) + + if x[-1]>x[-2]: + list_of_maxima.append(len(x)-1) + return list_of_maxima + +#def main(): + #x = [1, 3, -2, 0, 2, 1] + #x = [-1, -1, 0, -1] +# x = [4,2,1,3,1,5] + #x = [1, 2,2,1] + #x = input("enter sequence: ") + #print( type(x)) +# print(find_maxima(x)) + +#if __name__ == '__main__': + #main()