Skip to content

Commit 6148fc0

Browse files
feat: LeetCode 3062 in TypeScript
1 parent a86e644 commit 6148fc0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lesson_12/structs_ts/src/lesson12.ts

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

0 commit comments

Comments
 (0)