Skip to content

Instantly share code, notes, and snippets.

@TheGloriousGenesis
Created May 4, 2020 21:50
Show Gist options
  • Save TheGloriousGenesis/0eba56ddb667541a0b5321470569ad43 to your computer and use it in GitHub Desktop.
Save TheGloriousGenesis/0eba56ddb667541a0b5321470569ad43 to your computer and use it in GitHub Desktop.
Uncoupled Integer
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int result = 0;
while(scanner.hasNext()) {
for (String i: scanner.next().split(",")) {
/** XOR: when you XOR with a integer an even number of times
* your return value will be 0 or whatever you started with.
* E.g A ^ B ^ B = A. Hence can iterate through the array and
* only odd one out will remain as everything else is in pairs!
**/
result = result ^ Integer.parseInt(i.trim());
}
}
System.out.println(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment