File tree Expand file tree Collapse file tree 1 file changed +10
-16
lines changed Expand file tree Collapse file tree 1 file changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -6,26 +6,20 @@ 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
- const oddPoints = 0 ;
10
- const evenPoints = 0 ;
9
+ let oddPoints = 0 ;
10
+ let evenPoints = 0 ;
11
11
12
- // ListNode current = head;
13
- class ListNode {
14
- current : null | undefined ;
15
- costructor ( head = null ) {
16
- this . current = head ;
12
+ let current = head ;
13
+
14
+ while ( current != null && current . next != null ) {
15
+ if ( current . val > current . next . val ) {
16
+ evenPoints ++ ;
17
+ } else if ( current . val < current . next . val ) {
18
+ oddPoints ++ ;
17
19
}
20
+ // current = current.next.next;
18
21
}
19
22
20
- // while(current != null && current.next != null) {
21
- // if (current.val > current.next.val) {
22
- // evenPoints++;
23
- // } else if (current.val < current.next.val) {
24
- // oddPoints++;
25
- // }
26
- // current = current.next.next;
27
- // }
28
-
29
23
if ( oddPoints > evenPoints ) {
30
24
return "Odd" ;
31
25
} else if ( evenPoints > oddPoints ) {
You can’t perform that action at this time.
0 commit comments