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,23 @@ 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
+ ListNode current = head ;
11
+ int evenSide = 0 ;
12
+ int oddSide = 0 ;
13
+ while (current != null && current .next != null ) {
14
+ if (current .val > current .next .val ) {
15
+ evenSide ++;
16
+ } else if (current .val < current .next .val ) {
17
+ oddSide ++;
18
+ }
19
+ current = current .next .next ;
20
+ }
21
+ if (evenSide > oddSide ) {
22
+ return "Even" ;
23
+ } else if (evenSide < oddSide ) {
24
+ return "Odd" ;
25
+ } else {
26
+ return "Tie" ;
27
+ }
11
28
}
12
29
}
Original file line number Diff line number Diff line change @@ -9,18 +9,21 @@ public Stack() {
9
9
}
10
10
11
11
public void push (int value ) {
12
- // Your code here
12
+ ListNode tophat = new ListNode (value );
13
+ tophat .next = top ;
14
+ top = tophat ;
13
15
}
14
16
15
17
public int pop () {
16
- return 0 ;
18
+ top = top .next ;
19
+ return top .val ;
17
20
}
18
21
19
22
public int peek () {
20
- return 0 ;
23
+ return top . val ;
21
24
}
22
25
23
26
public boolean isEmpty () {
24
- return true ;
27
+ return top == null ;
25
28
}
26
29
}
You can’t perform that action at this time.
0 commit comments