Skip to content

Commit 3824f05

Browse files
committed
Feat: Adds, NileJackson's extra credit for lesson12.ts
1 parent 32f5984 commit 3824f05

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,30 @@ export class Lesson12 {
55
* Provide the solution to LeetCode 3062 here:
66
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
77
*/
8-
public gameResult(head: ListNode | null): string {
9-
return '';
8+
public gameResult(head: ListNode | null): String {
9+
if (!head) return "Tie";
10+
11+
12+
let current: ListNode | null = head;
13+
const scores: number[] = [0, 0];
14+
15+
while (current && current.next) {
16+
if (current.val !== current.next.val && current.val % 2 == 0) {
17+
if (current.val > current.next.val) {
18+
scores[0]++;
19+
} else {
20+
scores[1]++;
21+
}
22+
}
23+
current = current.next;
24+
}
25+
if(scores[0] > scores[1]) {
26+
return "Even";
27+
} else if (scores[0] < scores[1]) {
28+
return "Odd";
29+
} else {
30+
return "Tie";
1031
}
1132
}
33+
}
34+

0 commit comments

Comments
 (0)