Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q15-
- Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
- Find the unique number.
- Ans-import java.io.*;
- import java.util.*;
- class Main {
- public static void main (String[] args) {
- Scanner inputScanner = new Scanner(System.in);
- int n = inputScanner.nextInt();
- int A[] = new int[n];
- int xorResult = 0;
- for(int i=0;i<n;i++){
- A[i] = inputScanner.nextInt();
- xorResult = xorResult^ A[i];
- }
- System.out.print(xorResult);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement