https://www.hackerrank.com/challenges/lonely-integer
There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once.
https://codepair.hackerrank.com/paper/qz0v9rSh?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6ImplZmZlcnl5dWFuIiwiZW1haWwiOiJ5dWFueXVuLmtlbm55QGdtYWlsLmNvbSJ9
public static void main(String[] args) throws IOException {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
boolean arr[] = new boolean[101];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int a = Integer.parseInt(st.nextToken());
arr[a] = !arr[a];
}
for (int i = 0; i < 101; i++) {
if(arr[i]) {
System.out.println(i);
break;
}
}
}
catch(Exception e) {
}
There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once.
https://codepair.hackerrank.com/paper/qz0v9rSh?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6ImplZmZlcnl5dWFuIiwiZW1haWwiOiJ5dWFueXVuLmtlbm55QGdtYWlsLmNvbSJ9
public static void main(String[] args) throws IOException {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
boolean arr[] = new boolean[101];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int a = Integer.parseInt(st.nextToken());
arr[a] = !arr[a];
}
for (int i = 0; i < 101; i++) {
if(arr[i]) {
System.out.println(i);
break;
}
}
}
catch(Exception e) {
}