Skip to content

Commit

Permalink
Merge pull request #183 from Soumita072/patch-1
Browse files Browse the repository at this point in the history
Create gfg_potd_18Oct_2024.java
  • Loading branch information
Gyanthakur authored Oct 20, 2024
2 parents fbe809b + be02df4 commit 1eb768a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions october_2024/gfg_potd_18Oct_2024.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.*;

class Solution {
public int getSingle(int[] arr) {
// Using XOR to find the number occurring an odd number of times
int result = 0;
for (int num : arr) {
result ^= num;
}
return result;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = Integer.parseInt(scanner.nextLine());

while (t-- > 0) {
String input = scanner.nextLine();
String[] parts = input.split(" ");
int[] arr = new int[parts.length];

for (int i = 0; i < parts.length; i++) {
arr[i] = Integer.parseInt(parts[i]);
}

Solution obj = new Solution();
int res = obj.getSingle(arr);
System.out.println(res);
}

scanner.close();
}
}

0 comments on commit 1eb768a

Please sign in to comment.