Skip to content

Commit 4c20140

Browse files
committed
Feat: fix for lesson12.ts files
1 parent 004dd16 commit 4c20140

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
21
import { ListNode } from './list_node.js';
32

43
export 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

lesson_12/structs_ts/src/stack.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import { ListNode } from './list_node.js';
23

34
export 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
}

0 commit comments

Comments
 (0)