Created
January 11, 2021 01:55
-
-
Save thmain/8d40e36395fc8e6611d9c3832ad1e6f6 to your computer and use it in GitHub Desktop.
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.util.Arrays; | |
public class ExtraElementInTwoArrays { | |
public static void getExtraElement(int [] arrA, int [] arrB){ | |
int extraElement = 0; | |
for (int i = 0; i <arrA.length ; i++) | |
extraElement ^= arrA[i]; | |
for (int i = 0; i <arrB.length ; i++) | |
extraElement ^= arrB[i]; | |
System.out.println("Array A: " + Arrays.toString(arrA)); | |
System.out.println("Array B: " + Arrays.toString(arrB)); | |
System.out.println("Extra Element: " + extraElement); | |
} | |
public static void main(String[] args) { | |
int [] arrA = {3, 4, 5, 2, 9, 6}; | |
int [] arrB = {4, 3, 2, 9, 5, 7, 6}; | |
getExtraElement(arrA, arrB); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment