Skip to content

Commit f9b7d83

Browse files
committed
Feat: Modified two files of lesson12 by Hummad Tanweer
1 parent 39c8f59 commit f9b7d83

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@ public class Lesson12 {
66
* Provide the solution to LeetCode 3062 here:
77
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
88
*/
9+
public Lesson12() {}
10+
911
public String gameResult(ListNode head) {
10-
return null;
12+
int evenPoints = 0;
13+
int oddPoints = 0;
14+
while (head != null) {
15+
16+
if (head.val > head.next.val) {
17+
evenPoints++;
18+
} else if (head.val < head.next.val) {
19+
oddPoints++;
20+
}
21+
head = head.next.next;
22+
}
23+
if (evenPoints > oddPoints) {
24+
return "Even";
25+
} else if (oddPoints > evenPoints) {
26+
return "Odd";
27+
} else return "Tie";
1128
}
12-
}
29+
}

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

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

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
}

0 commit comments

Comments
 (0)