Skip to content

Instantly share code, notes, and snippets.

@feliperazeek
Created October 18, 2016 05:13
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 feliperazeek/e333f9498842b356b5f4b271f5a36378 to your computer and use it in GitHub Desktop.
Save feliperazeek/e333f9498842b356b5f4b271f5a36378 to your computer and use it in GitHub Desktop.
HackerRank - Cracking the Code Interview - Bit Manipulation: Lonely Integer (https://www.hackerrank.com/challenges/ctci-lonely-integer)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static int lonelyInteger(int[] a) {
int i = 0;
for (int eh : a) {
i = i ^ eh;
}
return i;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[n];
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
System.out.println(lonelyInteger(a));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment