Skip to content

Commit aab1baa

Browse files
author
“A1-4U2T1NN”
committed
feat: reconstructed lesson 12 assignment
1 parent eade00f commit aab1baa

File tree

1 file changed

+34
-6
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+34
-6
lines changed
Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
package com.codedifferently.lesson12;
22

3+
34
public class Lesson12 {
45

5-
/**
6-
* Provide the solution to LeetCode 3062 here:
7-
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8-
*/
9-
public String gameResult(ListNode head) {
10-
return null;
6+
7+
/**
8+
* Provide the solution to LeetCode 3062 here:
9+
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
10+
*/
11+
public String gameResult(ListNode head) {
12+
int evenCounter = 0; //Keeps track of even score
13+
int oddCounter = 0; //Keeps track of odd score
14+
15+
16+
int evenValue = head.val; //Makes the first even value to compare equal to the first number of the list
17+
int oddValue = head.next.val; //Makes the first odd value to compare equal to the second number of the list
18+
19+
20+
if ( evenValue > oddValue ) {
21+
evenCounter = evenCounter + 1;
22+
//Compares the even and odd value, adds 1 to even score if even is greater
23+
} else {
24+
oddCounter = ++oddCounter + 1;
25+
} //Compares the even and odd value, adds 1 to odd score if odd is greater
26+
27+
28+
if (evenCounter > oddCounter) {
29+
return "Even";
30+
//Compares the even and odd score, prints 'Even' if Evens score is greater
31+
} if (evenCounter < oddCounter) {
32+
return "Odd";
33+
//Compares the even and odd score, prints 'Odd' if odds score is greater
34+
} else {
35+
return "Tie";
36+
} //Compares the even and odd score, prints 'Tie' if the two scores are equal
37+
1138
}
39+
1240
}

0 commit comments

Comments
 (0)