Last active
August 26, 2017 17:56
-
-
Save thmain/b002514fd38537b5d725cb2fa1888d4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EveryElementsRepeatedButOne { | |
public static void findUsingXOR(int [] a){ | |
if(a.length==0) | |
return; | |
int xor = a[0]; | |
for (int i = 1; i <a.length ; i++) { | |
xor ^= a[i]; | |
} | |
System.out.println("Element appear only once in array - " + xor); | |
} | |
public static void main(String[] args) { | |
int [] a = { 1,5,6,2,1,6,4,3,2,5,3}; | |
findUsingXOR(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment