deno.land / x / masx200_leetcode_test@10.6.5 / yong-liang-ge-zhan-shi-xian-dui-lie-lcof / 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
25
26
27
28
29
30
// deno-lint-ignore no-explicit-anyexport default interface CQueue<T = any> { appendTail: (value: T) => void; deleteHead: () => T | number;}
// deno-lint-ignore no-explicit-anyexport default function CQueue<T = any>(): CQueue<T> { const inStack: Array<T> = []; const outStack: Array<T> = []; function deleteHead(): T | number { if (!outStack.length) { if (!inStack.length) { return -1; } in2out(); } return outStack.pop() as T; } function appendTail(value: T): void { inStack.push(value); } function in2out() { while (inStack.length) { outStack.push(inStack.pop() as T); } } return { appendTail, deleteHead };}
masx200_leetcode_test

Version Info

Tagged at
a year ago