You are viewing a single comment's thread. Return to all comments →
When xor same elements eliminate 2 ^ 3 ^ 2 ^ 3 ^ 6 = 6 First write examples and try solve step by step and you will see the big picture.
public static int sansaXor(List<Integer> arr) { int n = arr.size(); int ans = 0; if(n % 2 != 0){ for(int i = 0; i < arr.size(); i+=2) ans ^= arr.get(i); return ans; }else return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sansa and XOR
You are viewing a single comment's thread. Return to all comments →
When xor same elements eliminate 2 ^ 3 ^ 2 ^ 3 ^ 6 = 6 First write examples and try solve step by step and you will see the big picture.