File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,30 @@ export class Lesson12 {
5
5
* Provide the solution to LeetCode 3062 here:
6
6
* https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
7
7
*/
8
- public gameResult ( head : ListNode | null ) : string {
9
- return '' ;
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 ) {
16
+ if ( current . val !== current . next . val && current . val % 2 == 0 ) {
17
+ if ( current . val > current . next . val ) {
18
+ scores [ 0 ] ++ ;
19
+ } else {
20
+ scores [ 1 ] ++ ;
21
+ }
22
+ }
23
+ current = current . next ;
24
+ }
25
+ if ( scores [ 0 ] > scores [ 1 ] ) {
26
+ return "Even" ;
27
+ } else if ( scores [ 0 ] < scores [ 1 ] ) {
28
+ return "Odd" ;
29
+ } else {
30
+ return "Tie" ;
10
31
}
11
32
}
33
+ }
34
+
You can’t perform that action at this time.
0 commit comments