Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 02807a9

Browse files
author
Ram swaroop
committed
two repeating elements : done
1 parent 84cc7a4 commit 02807a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/me/ramswaroop/arrays/TwoRepeatingElements.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static int[] getTwoRepeatingElements(int[] a) {
1515
int xor = a[0];
1616
int rightMostSetBit;
1717
int x = 0, y = 0;
18+
1819
for (int i = 1; i < a.length; i++) {
1920
xor ^= a[i];
2021
}
@@ -24,15 +25,15 @@ public static int[] getTwoRepeatingElements(int[] a) {
2425
rightMostSetBit = xor & ~(xor - 1);
2526

2627
for (int i = 0; i < a.length; i++) {
27-
if ((a[i] & rightMostSetBit) == 1) {
28+
if ((a[i] & rightMostSetBit) == 0) {
2829
x ^= a[i];
2930
} else {
3031
y ^= a[i];
3132
}
3233
}
3334

3435
for (int i = 1; i <= a.length - 2; i++) {
35-
if ((i & rightMostSetBit) == 1) {
36+
if ((i & rightMostSetBit) == 0) {
3637
x ^= i;
3738
} else {
3839
y ^= i;

0 commit comments

Comments
 (0)