File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 1- /* eslint-disable @typescript-eslint/no-unused-vars */
21import { ListNode } from './list_node.js' ;
32
43export class Lesson12 {
5- push ( scores : number ) : void {
6- throw new Error ( 'Not implemented' ) ;
7- }
84 /**
95 * Provide the solution to LeetCode 3062 here:
106 * https://github.com/yang-su2000/Leetcode-algorithm-practice/tree/master/3062-winner-of-the-linked-list-game
Original file line number Diff line number Diff line change 1+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
12import { ListNode } from './list_node.js' ;
23
34export class Stack {
@@ -7,19 +8,24 @@ export class Stack {
78 this . top = undefined ;
89 }
910
10- push ( number : number ) : void {
11- throw new Error ( 'Not implemented' ) ;
11+ push ( value : number ) : void {
12+ const newNode = new ListNode ( value ) ;
13+ newNode . next = this . top ;
14+ this . top = newNode ;
1215 }
1316
1417 pop ( ) : number | undefined {
15- throw new Error ( 'Not implemented' ) ;
18+ if ( this . isEmpty ( ) ) return undefined ;
19+ const value = this . top ! . value ;
20+ this . top = this . top ! . next ;
21+ return value ;
1622 }
1723
1824 peek ( ) : number | null {
19- throw new Error ( 'Not implemented' ) ;
25+ return this . isEmpty ( ) ? null : this . top ?. value ;
2026 }
2127
2228 isEmpty ( ) : boolean {
23- throw new Error ( 'Not implemented' ) ;
29+ return this . top === undefined ;
2430 }
2531}
You can’t perform that action at this time.
0 commit comments