Skip to content

Commit 9d48445

Browse files
committed
feat: Lesson 12 Game Result / Stack by Dwight Blue
1 parent 439780a commit 9d48445

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,34 @@
22

33
public class Lesson12 {
44

5+
public Lesson12() {
6+
7+
}
8+
59
/**
610
* Provide the solution to LeetCode 3062 here:
711
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
812
*/
913
public String gameResult(ListNode head) {
10-
return null;
11-
}
12-
}
14+
var o = 0;
15+
var e = 0;
16+
while (head != null){
17+
if (head.val > head.next.val){
18+
e++;
19+
}
20+
else{
21+
o++;
22+
}
23+
head = head.next.next;
24+
}
25+
if ( e > o) {
26+
return "Even";
27+
} else if ( e<o) {
28+
return "Odd";
29+
}
30+
else
31+
return "Tie";
32+
33+
}
34+
35+
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package com.codedifferently.lesson12;
22

3+
34
/** Implement the below Stack by providing code for the class methods. */
45
public class Stack {
56
private ListNode top;
67

78
public Stack() {
89
this.top = null;
910
}
10-
1111
public void push(int value) {
12-
// Your code here
12+
ListNode newTop = new ListNode (value);
13+
newTop.next = top;
14+
top = newTop;
1315
}
1416

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

1923
public int peek() {
20-
return 0;
24+
var headVal = top.val;
25+
return headVal;
2126
}
2227

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

0 commit comments

Comments
 (0)