File tree Expand file tree Collapse file tree 1 file changed +21
-19
lines changed Expand file tree Collapse file tree 1 file changed +21
-19
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
2
import { ListNode } from './list_node.js' ;
2
3
3
4
export class Lesson12 {
5
+ push ( scores : number ) : void {
6
+ throw new Error ( 'Not implemented' ) ;
7
+ }
4
8
/**
5
9
* Provide the solution to LeetCode 3062 here:
6
10
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
7
11
*/
8
- public gameResult ( head : ListNode | null ) : String {
9
- if ( ! head ) return "Tie" ;
10
-
11
-
12
- let current : ListNode | null = head ;
13
- const scores : number [ ] = [ 0 , 0 ] ;
14
-
15
- while ( current && current . next ) {
12
+ public gameResult ( head : ListNode | null ) : string {
13
+ if ( ! head ) return 'Tie' ;
14
+
15
+ let current : ListNode | null = head ;
16
+ const scores : number [ ] = [ 0 , 0 ] ;
17
+
18
+ while ( current && current . next ) {
16
19
if ( current . val !== current . next . val && current . val % 2 == 0 ) {
17
20
if ( current . val > current . next . val ) {
18
21
scores [ 0 ] ++ ;
19
- } else {
20
- scores [ 1 ] ++ ;
21
- }
22
+ } else {
23
+ scores [ 1 ] ++ ;
24
+ }
22
25
}
23
26
current = current . next ;
24
27
}
25
- if ( scores [ 0 ] > scores [ 1 ] ) {
26
- return "Even" ;
27
- } else if ( scores [ 0 ] < scores [ 1 ] ) {
28
- return "Odd" ;
29
- } else {
30
- return "Tie" ;
28
+ if ( scores [ 0 ] > scores [ 1 ] ) {
29
+ return 'Even' ;
30
+ } else if ( scores [ 0 ] < scores [ 1 ] ) {
31
+ return 'Odd' ;
32
+ } else {
33
+ return 'Tie' ;
34
+ }
31
35
}
32
36
}
33
- }
34
-
You can’t perform that action at this time.
0 commit comments