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
|
806 Discussions
|
Please Login in order to post a comment
Here's a simple approach using XOR operator:
PYTHON3
I tried a different approach using Collections.Counter and a comprehension list, returning its first value if exists. Additionally, added an optional parameter that allows to change the amount of repeats that we are looking for.
A solution in python using the bitwise XOR operator. Works because when the loop cycles through a number twice, that bit flips back to zero (effectively erasing it). At the end, it's a matter of seeing which bit is the last one standing and then converting it back to base 10 based on its position.