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