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 */
12import { ListNode } from './list_node.js' ;
23
34export class Lesson12 {
5+ push ( scores : number ) : void {
6+ throw new Error ( 'Not implemented' ) ;
7+ }
48 /**
59 * Provide the solution to LeetCode 3062 here:
610 * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
711 */
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 ) {
1619 if ( current . val !== current . next . val && current . val % 2 == 0 ) {
1720 if ( current . val > current . next . val ) {
1821 scores [ 0 ] ++ ;
19- } else {
20- scores [ 1 ] ++ ;
21- }
22+ } else {
23+ scores [ 1 ] ++ ;
24+ }
2225 }
2326 current = current . next ;
2427 }
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+ }
3135 }
3236}
33- }
34-
You can’t perform that action at this time.
0 commit comments