File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -16,27 +16,23 @@ public String gameResult(ListNode head) {
16
16
// Check each pair of nodes (odd and even):
17
17
// compare their values
18
18
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 ){
21
21
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 ){
25
23
oddPoints ++;
26
24
}
27
-
28
25
current = current .next .next ;
29
26
}
30
27
// Decide the winner
31
28
// compare the points and choose the winner or tie
32
29
if (oddPoints > evenPoints ) {
33
- return ( "Team odd wins!" ) ;
30
+ return "Odd" ;
34
31
} else if (evenPoints > oddPoints ){
35
- return ( "Team Even wins" ) ;
32
+ return " Even" ;
36
33
} else {
37
- return ("It's a tie" );
38
- }
39
-
34
+ return "Tie" ;
35
+ }
40
36
}
41
37
}
42
38
You can’t perform that action at this time.
0 commit comments