File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
3
public class Lesson12 {
4
-
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
4
public String gameResult (ListNode head ) {
10
- return null ;
5
+ int result [] = new int [] {0 , 0 };
6
+ while (head .next != null ) {
7
+ if (head .val != head .next .val && head .val % 2 == 0 ) {
8
+ if (head .val > head .next .val ) result [head .val % 2 ] += 1 ;
9
+ else result [head .next .val % 2 ] += 1 ;
10
+ }
11
+ head = head .next ;
12
+ }
13
+ return (result [0 ] == result [1 ]) ? "Tie" : (result [0 ] > result [1 ] ? "Even" : "Odd" );
11
14
}
12
15
}
Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
- /** Implement the below Stack by providing code for the class methods. */
4
3
public class Stack {
5
4
private ListNode top ;
6
5
@@ -9,18 +8,30 @@ public Stack() {
9
8
}
10
9
11
10
public void push (int value ) {
12
- // Your code here
11
+ ListNode newNode = new ListNode (value );
12
+ newNode .next = top ;
13
+ top = newNode ;
13
14
}
14
15
15
16
public int pop () {
16
- return 0 ;
17
+ int topmostValue = 0 ;
18
+ if (isEmpty ()) {
19
+ return Integer .parseInt (null );
20
+ } else {
21
+ topmostValue = top .val ;
22
+ top = top .next ;
23
+ return topmostValue ;
24
+ }
17
25
}
18
26
19
27
public int peek () {
20
- return 0 ;
28
+ if (isEmpty ()) {
29
+ return Integer .parseInt (null );
30
+ }
31
+ return top .val ;
21
32
}
22
33
23
34
public boolean isEmpty () {
24
- return true ;
35
+ return top == null ;
25
36
}
26
37
}
You can’t perform that action at this time.
0 commit comments