File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,22 @@ 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
+ while (head != null && head .next != null ) {
13
+ if (head .val > head .next .val ) {
14
+ even ++;
15
+ } else {
16
+ odd ++;
17
+ }
18
+ head = head .next .next ;
19
+ }
20
+ if (even == odd ) {
21
+ return ("Tie" );
22
+ } else if (even > odd ) {
23
+ return ("Even" );
24
+ } else {
25
+ return ("Odd" );
26
+ }
11
27
}
12
28
}
Original file line number Diff line number Diff line change @@ -10,17 +10,23 @@ public Stack() {
10
10
11
11
public void push (int value ) {
12
12
// Your code here
13
+ ListNode top2 = new ListNode (value );
14
+ top2 .next = top ;
15
+ top = top2 ;
13
16
}
14
17
15
18
public int pop () {
16
- return 0 ;
19
+ int topvalue = top .val ;
20
+ top = top .next ;
21
+
22
+ return topvalue ;
17
23
}
18
24
19
25
public int peek () {
20
- return 0 ;
26
+ return top . val ;
21
27
}
22
28
23
29
public boolean isEmpty () {
24
- return true ;
30
+ return top == null
25
31
}
26
32
}
You can’t perform that action at this time.
0 commit comments