Skip to content

Commit 6ea2309

Browse files
committed
feat: implemented TS method for gameResult
1 parent cc90062 commit 6ea2309

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ 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 oddPoints: number = 0;
10+
let evenPoints: number = 0;
11+
12+
let curr = head;
13+
14+
while (curr != null && curr.next != null) {
15+
if (curr.val > curr.next.val) {
16+
evenPoints++;
17+
} else if (curr.val < curr.next.val) {
18+
oddPoints++;
19+
}
20+
curr = curr.next.next as ListNode;
21+
}
22+
23+
if (oddPoints > evenPoints) {
24+
return "Odd";
25+
} else if (oddPoints < evenPoints) {
26+
return "Even";
27+
} else {
28+
return "Tie";
29+
}
1030
}
1131
}
32+

0 commit comments

Comments
 (0)