Skip to content

Instantly share code, notes, and snippets.

View ankit167's full-sized avatar
🎯
Focusing

Ankit Agarwal ankit167

🎯
Focusing
View GitHub Profile
@ankit167
ankit167 / test.java
Created May 9, 2021 09:56
Find two elements in the array that are not repeated
// Input: 2 1 7 4 5 4 7 1
// Output: 2 5
public void findTwoElements(int[] a) {
int xor = 0, x = 0, y = 0, rsb;
for (int i = 0; i < a.length; i++) {
xor = xor ^ a[i]
}
rsb = xor & ~(xor-1);
public int singleNumber(int[] nums) {
int xor = 0;
for (int i = 0; i < nums.length; i++) {
xor = xor ^ nums[i];
}
return xor;
}