File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,24 @@ public class Lesson12 {
7
7
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
8
*/
9
9
public String gameResult (ListNode head ) {
10
- return null ;
10
+ int even = 0 ;
11
+ int odd = 0 ;
12
+
13
+ while (head != null && head .next != null ){
14
+ if (head .val > head .next .val ) {
15
+ even ++;
16
+ } else if (head .val < head .next .val ) {
17
+ odd ++;
18
+ }
19
+ head = head .next .next ;
20
+ }
21
+
22
+ if (even > odd ){
23
+ return "Even" ;
24
+ }
25
+ else if (even < odd ){
26
+ return "Odd" ;
27
+ }
28
+ return "Tie" ;
11
29
}
12
30
}
Original file line number Diff line number Diff line change @@ -9,18 +9,20 @@ public Stack() {
9
9
}
10
10
11
11
public void push (int value ) {
12
- // Your code here
12
+ top = new ListNode ( value , top );
13
13
}
14
14
15
15
public int pop () {
16
- return 0 ;
16
+ int value = top .val ;
17
+ top = top .next ;
18
+ return value ;
17
19
}
18
20
19
21
public int peek () {
20
- return 0 ;
22
+ return top . val ;
21
23
}
22
24
23
25
public boolean isEmpty () {
24
- return true ;
26
+ return top == null ;
25
27
}
26
28
}
You can’t perform that action at this time.
0 commit comments