Add NumberAppearingOddTimes algorithm (#5633)

This commit is contained in:
Lakshyajeet Singh Goyal
2024-10-09 00:12:24 +05:30
committed by GitHub
parent f3b2a94e74
commit b54cc21ade
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.thealgorithms.bitmanipulation;
/**
* Find the Number Appearing Odd Times in an array
* @author Lakshyajeet Singh Goyal (https://github.com/DarkMatter-999)
*/
public final class NumberAppearingOddTimes {
private NumberAppearingOddTimes() {
}
public static int findOddOccurrence(int[] arr) {
int result = 0;
// XOR all elements in the array
for (int num : arr) {
result ^= num;
}
return result;
}
}