Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created March 27, 2021 21:12
Show Gist options
  • Save Clivern/09b5d82c6e3e3fa1d518f9fd13a68fbb to your computer and use it in GitHub Desktop.
Save Clivern/09b5d82c6e3e3fa1d518f9fd13a68fbb to your computer and use it in GitHub Desktop.
Get array peak values
def solution(A):
count = 0
peaks = []
for i in range(len(A)):
if i > 0 and i != (len(A)-1) and A[i] > A[i-1] and A[i] > A[i+1] and A[i] not in peaks:
peaks.append(A[i])
count += 1
return count
if __name__ == '__main__':
assert solution([2, 2, 3, 2, 1]) == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment