Skip to content

Commit 9807ec1

Browse files
committed
feat: adds Lesson12.java && Stack.java for NileJackson
1 parent 439780a commit 9807ec1

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Lesson12.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,39 @@ public class Lesson12 {
99
public String gameResult(ListNode head) {
1010
return null;
1111
}
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+
}
1247
}

lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ public Stack() {
99
}
1010

1111
public void push(int value) {
12-
// Your code here
12+
ListNode newNode = new ListNode(value);
13+
newNode.next = top;
14+
top = newNode;
1315
}
1416

1517
public int pop() {
16-
return 0;
18+
int value = top.val;
19+
top = top.next;
20+
return value;
1721
}
1822

1923
public int peek() {
20-
return 0;
24+
return top.val;
2125
}
2226

2327
public boolean isEmpty() {
24-
return true;
28+
return top == null;
2529
}
2630
}

0 commit comments

Comments
 (0)