Skip to content

Commit 2ed323a

Browse files
author
“Tezz03”
committed
feat: mbLesson_12
1 parent d3239c0 commit 2ed323a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ public class Lesson12 {
77
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
88
*/
99
public String gameResult(ListNode head) {
10-
return null;
10+
int even = 0;
11+
int odd = 0;
12+
13+
while (head != null) {
14+
if (head.val > head.next.val) {
15+
even++;
16+
17+
} else if (head.val < head.next.val) {
18+
odd++;
19+
}
20+
head = head.next.next;
21+
}
22+
if (even > odd) {
23+
return "Even";
24+
}
25+
if (even < odd) {
26+
return "Odd";
27+
}
28+
return "Tie";
1129
}
1230
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ public Stack() {
1010

1111
public void push(int value) {
1212
// Your code here
13+
ListNode newNode = new ListNode(value);
14+
newNode.next = top;
15+
top = newNode;
1316
}
1417

1518
public int pop() {
16-
return 0;
19+
int result = top.val;
20+
top = top.next;
21+
return result;
1722
}
1823

1924
public int peek() {
20-
return 0;
25+
return top.val;
2126
}
2227

2328
public boolean isEmpty() {
24-
return true;
29+
return top == null;
2530
}
2631
}

0 commit comments

Comments
 (0)