Last active
January 17, 2017 20:43
-
-
Save gbazilio/212c36379c6c33c865898205d922287e to your computer and use it in GitHub Desktop.
Codility - Odd occurrences
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 solution(A): | |
A = sorted(A) | |
for index in range(0, len(A), 2): | |
next_index = index+1 | |
if next_index >= len(A) or A[index] != A[index+1]: | |
return A[index] |
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 solution(A): | |
result = A[0] | |
for index in range(1, len(A)): | |
result = result ^ A[index] | |
return result |
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 solution(A): | |
return reduce(lambda x, y: x^y, A) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment