Swap using XOR
Java
Easy
6 views
Problem Description
Task: swap a[i] and a[j] using XOR (only if i!=j).
Output Format
In-place update
Constraints
Avoid when i==j.
Official Solution
static void xorSwap(int[] a,int i,int j){if(i==j) return;a[i]^=a[j];a[j]^=a[i];a[i]^=a[j];}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!