Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active August 26, 2017 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/b002514fd38537b5d725cb2fa1888d4b to your computer and use it in GitHub Desktop.
Save thmain/b002514fd38537b5d725cb2fa1888d4b to your computer and use it in GitHub Desktop.
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