Skip to content

Commit 7c6d0b1

Browse files
author
AmiyahJo
committed
fix: adding a point if one of the even or odd indexed node is higher
1 parent eedad00 commit 7c6d0b1

File tree

1 file changed

+7
-11
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+7
-11
lines changed

lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,23 @@ public String gameResult(ListNode head) {
1616
// Check each pair of nodes (odd and even):
1717
// compare their values
1818
while (current != null && current.next != null) {
19-
// add a point to "Even" if the odd-indexed node is higher
20-
if (current.val < current.next.val){
19+
// add a point to "Even" if the odd-indexed node is higher and vice versa
20+
if (current.val > current.next.val){
2121
evenPoints++;
22-
}
23-
//add a point to "Odd" if the even-indexed node is higher
24-
else if (current.val > current.next.val){
22+
} else if (current.val < current.next.val){
2523
oddPoints++;
2624
}
27-
2825
current = current.next.next;
2926
}
3027
// Decide the winner
3128
// compare the points and choose the winner or tie
3229
if (oddPoints > evenPoints) {
33-
return("Team odd wins!");
30+
return "Odd";
3431
} else if (evenPoints > oddPoints){
35-
return("Team Even wins");
32+
return "Even";
3633
} else {
37-
return ("It's a tie");
38-
}
39-
34+
return "Tie";
35+
}
4036
}
4137
}
4238

0 commit comments

Comments
 (0)