Find two single numbers
Java
Hard
4 views
Problem Description
Task: every number appears twice except two numbers. Return the two unique numbers.
Output Format
Return value
Constraints
Use xor split by lowbit.
Official Solution
static int[] twoSingles(int[] a){int x=0;for(int v:a) x^=v;int lb=x & -x;int p=0,q=0;for(int v:a){if((v&lb)==0) p^=v; else q^=v;}return new int[]{p,q};}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!