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
Lonely Integer
Sort by
recency
|
572 Discussions
|
Please Login in order to post a comment
Java:
Using bitwise operator will be time complexity of O(n) without requiring addition memory space.
when we use xor between same number,
therefore,
conclusion: xor with same number provide zero.
when we use xor between any value and zero,
therefore,
conclusion: xor with a number provide the same number. No effect when we xor a value with zero
Also, 7^4^7 is same as 7^7^4
Now with more values,
Since hackerrank gurantees only one unique element always there, so we can just use xor across the list and return the final output.
Perl:
Here is my c++ solution, you can watch the vidéo explanation here : https://youtu.be/E4PVCUOdeXM