We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Lonely Integer
- Discussions
Lonely Integer
Lonely Integer
Sort by
recency
|
445 Discussions
|
Please Login in order to post a comment
def lonelyinteger(a): # Write your code here for i in a: if a.count(i)==1: result=i return i
Hi
I have got one invalid test case here where the array is 0 0 1 2 1 , so the unique element count should be 3 but its coming 2 as expected output ,causing my tests to fail , anybody faced this or correct me?
My solution in Rust, it takes advantage of the XOR properties. they key is that every has only one duplicate eccept one (correct me if I'm wrong) and XOR is commutative and associative:
def lonelyinteger(a): for n in a: if a.count(n) == 1: return n