We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84cc7a4 commit 02807a9Copy full SHA for 02807a9
src/me/ramswaroop/arrays/TwoRepeatingElements.java
@@ -15,6 +15,7 @@ public static int[] getTwoRepeatingElements(int[] a) {
15
int xor = a[0];
16
int rightMostSetBit;
17
int x = 0, y = 0;
18
+
19
for (int i = 1; i < a.length; i++) {
20
xor ^= a[i];
21
}
@@ -24,15 +25,15 @@ public static int[] getTwoRepeatingElements(int[] a) {
24
25
rightMostSetBit = xor & ~(xor - 1);
26
27
for (int i = 0; i < a.length; i++) {
- if ((a[i] & rightMostSetBit) == 1) {
28
+ if ((a[i] & rightMostSetBit) == 0) {
29
x ^= a[i];
30
} else {
31
y ^= a[i];
32
33
34
35
for (int i = 1; i <= a.length - 2; i++) {
- if ((i & rightMostSetBit) == 1) {
36
+ if ((i & rightMostSetBit) == 0) {
37
x ^= i;
38
39
y ^= i;
0 commit comments