File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class Lesson12 {
4
4
5
+ public Lesson12 () {
6
+
7
+ }
8
+
5
9
/**
6
10
* Provide the solution to LeetCode 3062 here:
7
11
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
8
12
*/
9
13
public String gameResult (ListNode head ) {
10
- return null ;
11
- }
12
- }
14
+ var o = 0 ;
15
+ var e = 0 ;
16
+ while (head != null ){
17
+ if (head .val > head .next .val ){
18
+ e ++;
19
+ }
20
+ else {
21
+ o ++;
22
+ }
23
+ head = head .next .next ;
24
+ }
25
+ if ( e > o ) {
26
+ return "Even" ;
27
+ } else if ( e <o ) {
28
+ return "Odd" ;
29
+ }
30
+ else
31
+ return "Tie" ;
32
+
33
+ }
34
+
35
+ }
Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson12 ;
2
2
3
+
3
4
/** Implement the below Stack by providing code for the class methods. */
4
5
public class Stack {
5
6
private ListNode top ;
6
7
7
8
public Stack () {
8
9
this .top = null ;
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
}
32
+
You can’t perform that action at this time.
0 commit comments