Created
March 27, 2021 21:12
-
-
Save Clivern/09b5d82c6e3e3fa1d518f9fd13a68fbb to your computer and use it in GitHub Desktop.
Get array peak values
This file contains hidden or 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 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