Find single number (others twice)
Java
Hard
4 views
Problem Description
Task: in array where every number appears twice except one, return the single number using XOR.
Output Format
Return value
Constraints
O(n) time, O(1) space.
Official Solution
static int singleNumber(int[] a){int x=0;for(int v:a) x^=v;return x;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!