File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,23 @@ export class Lesson12 {
6
6
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
7
7
*/
8
8
public gameResult ( head : ListNode | null ) : string {
9
- return '' ;
9
+ 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
+ }
10
27
}
11
28
}
You can’t perform that action at this time.
0 commit comments