We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7252e6b commit 82b000eCopy full SHA for 82b000e
lesson_12/structs_ts/src/lesson12.ts
@@ -6,6 +6,23 @@ 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 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
27
}
28
0 commit comments