File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,26 @@ public class Lesson12 {
77 * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
88 */
99 public String gameResult (ListNode head ) {
10- return null ;
10+ int [] ls = new int [2 ];
11+ while (head != null && head .next != null ) {
12+ // Iterate through the linked list until the second last node
13+ if (head .val != head .next .val && head .val % 2 == 0 ) {
14+ // Check if we have different values and if the current value is even
15+ if (head .val > head .next .val ) {
16+ ls [head .val % 2 ] += 1 ;
17+ } else {
18+ ls [head .next .val % 2 ] += 1 ;
19+ }
20+ }
21+ head = head .next ;
22+ }
23+
24+ if (ls [0 ] > ls [1 ]) {
25+ return "Even" ;
26+ } else if (ls [0 ] == ls [1 ]) {
27+ return "Tie" ;
28+ } else {
29+ return "Odd" ;
30+ }
1131 }
1232}
You can’t perform that action at this time.
0 commit comments