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