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
|
406 Discussions
|
Please Login in order to post a comment
This problem is most optimally solved using bit manipulation. The XOR logical function returns 1 when both inputs are diferent and 0 when they're the same, so 3 ^ 3 = 0 because in 11 xor 11 all digits are the same and they cancel out, this way we'll end up with the following: 0 ^ {lonelyInteger} which is the lonelyInteger itself: Java code:
JAVASCRIPT
**Using XOR Operations ** function lonelyinteger(a) { // Write your code here let lonelyInteger = 0; for (let e of a) { lonelyInteger ^= e; } return lonelyInteger; } `
Java 8. Imperative
Java 8 Declarative