Last active
December 17, 2020 04:41
-
-
Save hrubantjakub1/1cb20c0e8cf551a48a7c1c956c130fe5 to your computer and use it in GitHub Desktop.
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
// find element without pair in array | |
def solution(A): | |
A.sort() | |
for index in range(0,len(A),2): | |
if A[index] != A[index+1]: | |
return A[index] | |
B = [5,6,2,9,2,3,6,7,3,1,7,9,1] | |
print(solution(B)) |
from collections import Counter
def solution(A):
oc = Counter(A)
for o in oc.keys():
if oc[o] % 2 ==1:
return o
Hey, I don't know whether you have modified yours or not but I have tried to modified yours and it is now giving 100% correct result according to codility
def solution(A):
A.sort()
for index in range(0,len(A),2):
boundary = len(A)-2
if index <boundary:
if A[index] != A[index+1]:
return A[index]
else:
return A[-1]cheers !!! happy coding
Can you explain to me?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I don't know whether you have modified yours or not but I have tried to modified yours and it is now giving 100% correct result according to codility
def solution(A):
A.sort()
for index in range(0,len(A),2):
boundary = len(A)-2
if index <boundary:
if A[index] != A[index+1]:
return A[index]
else:
return A[-1]
cheers !!! happy coding