Skip to content

Commit 82b000e

Browse files
committed
feat: Add Dasia's Game Results in ts
1 parent 7252e6b commit 82b000e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lesson_12/structs_ts/src/lesson12.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ export class Lesson12 {
66
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
77
*/
88
public gameResult(head: ListNode | null): string {
9-
return '';
9+
let current: ListNode| null = head;
10+
let evenPoints = 0;
11+
let oddPoints = 0;
12+
while (current !== null && current.next != null) {
13+
if (current.val > current.next.val) {
14+
evenPoints++;
15+
} else if (current.val < current.next.val) {
16+
oddPoints++;
17+
}
18+
current =current.next.next != undefined? current.next.next : null;
19+
}
20+
if (evenPoints > oddPoints) {
21+
return 'Even';
22+
} else if (oddPoints > evenPoints) {
23+
return 'Odd';
24+
} else {
25+
return 'Tie';
26+
}
1027
}
1128
}

0 commit comments

Comments
 (0)