given the input
20
1 3 5 7 9 11 13 15 17 19 21 2 4 6 8 10 12 14 16 18
and the two solutions (removed input class at the bottom)
public static void main(String[] args) throws IOException {
Kattio io = new Kattio();
int n = io.nextInt();
int o = 0; int e = 0;
for (int i = 0; i < n; i++) {
int j = io.nextInt();
if (j % 2 == 0) {e++;}
else {o++;}
}
if (o == e || e == o + 1) {io.println(n);}
else {
while (o > e) {
o -= 2; e++;
}
if (e > o + 1) {
e = o + 1;
}
}
io.println(e + o);
io.close();
}
public static void main(String[] args) throws IOException {
Kattio io = new Kattio();
int n = io.nextInt();
int o = 0; int e = 0;
for (int i = 0; i < n; i++) {
int j = io.nextInt();
if (j % 2 == 0) {e++;}
else {o++;}
}
if (o == e || e == o + 1) {io.println(n);}
else {
if (e > o + 1) {io.println(o * 2 + 1);}
else {
while (o > e) {
o -= 2; e++;
}
io.println(o * 2 + 1);
}
}
io.close();
}```
why does the first one print the correct answer, 18, and the second print the wrong answer, 19?
I can't see how the second solution differs from the first solution.
The first one just seems like a "smarter" way to do it.