File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12 Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,39 @@ public class Lesson12 {
9
9
public String gameResult (ListNode head ) {
10
10
return null ;
11
11
}
12
+
13
+ class ListNode {
14
+ int val ;
15
+ ListNode next ;
16
+
17
+ ListNode (int x ) {
18
+ val = x ;
19
+ }
20
+ }
21
+
22
+ class Solution {
23
+ public String gameResult (ListNode head ) {
24
+ int [] scores = new int [2 ];
25
+
26
+ while (head .next != null ) {
27
+ // Used ChatGpt to help complete this if statement-starting at the logical & operand
28
+ if (head .val != head .next .val && head .val % 2 == 0 ) {
29
+ if (head .val > head .next .val ) {
30
+ scores [head .val % 2 ]++;
31
+ // Gpt help ended at the line above
32
+ } else {
33
+ scores [head .next .val % 2 ]++;
34
+ }
35
+ }
36
+ head = head .next ;
37
+ }
38
+ if (scores [0 ] == scores [1 ]) {
39
+ return "Tie" ;
40
+ } else if (scores [0 ] > scores [1 ]) {
41
+ return "Even" ;
42
+ } else {
43
+ return "odd" ;
44
+ }
45
+ }
46
+ }
12
47
}
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