Skip to content

Commit acc2df0

Browse files
committed
staged changes to lesson_12
1 parent ea7f46e commit acc2df0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ 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 ListNode, current = head;
10+
let even = 0;
11+
let odd = 0;
12+
while (current != null && current.next != null) {
13+
let next: ListNode | null = null;
14+
if (head === null) {
15+
odd++;
16+
}
17+
if (current.val > nextNode.val) {
18+
even++;
19+
}
20+
current === nextNode.next;
21+
}
22+
if (even > odd) {
23+
return "Even";
24+
}
25+
if (even < odd) {
26+
return "Odd";
27+
}
28+
if (even === odd) {
29+
return "Tie";
30+
}
31+
return null;
1032
}
1133
}

0 commit comments

Comments
 (0)