Created
October 18, 2016 05:13
-
-
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)
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
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