We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a86e644 commit 6148fc0Copy full SHA for 6148fc0
lesson_12/structs_ts/src/lesson12.ts
@@ -6,6 +6,32 @@ export class Lesson12 {
6
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
7
*/
8
public gameResult(head: ListNode | null): string {
9
- return '';
+ 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
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";
36
}
37
0 commit comments