LeetCode75-136-Single-Number
🧠 Summary of Thoughts
Use the bitwise XOR (^) operation to cancel out duplicate numbers.
XOR has two important properties:
- a ^ a = 0 → same numbers cancel out
- a ^ 0 = a → zero does not affect the result
Every number that appears twice cancels itself out. The only number left is the one that appears once. We can also reorder the ^’s left and right number to cancel the duplicate out :)
✅ Code(Java)
1 | |
LeetCode75-136-Single-Number
https://powersixxx.github.io/leetcode-blog/2026/04/11/LeetCode75-136-Single-Number/