deno.land / x / masx200_leetcode_test@10.6.5 / min-stack / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export default MinStack;type MinStack = ReturnType<typeof MinStack>;function MinStack() { const stack = [] as [number, number][]; return { push(x: number): void { stack.push([x, Math.min(x, stack.at(-1)?.[1] ?? Infinity)]); }, pop(): void { stack.pop(); }, top(): number { const res = stack.at(-1)?.[0]; if (typeof res === "undefined") throw Error("empty stack"); return res; }, getMin(): number { const res = stack.at(-1)?.[1]; if (typeof res === "undefined") throw Error("empty stack"); return res; }, };}
masx200_leetcode_test

Version Info

Tagged at
a year ago