deno.land / x / masx200_leetcode_test@10.6.5 / implement-queue-using-stacks / index.ts
123456789101112131415161718192021222324252627282930313233343536// deno-lint-ignore no-explicit-anyexport default interface MyQueue<T = any> { empty: () => boolean; peek: () => T; pop: () => T; push: (x: T) => void;}
// deno-lint-ignore no-explicit-anyexport default function MyQueue<T = any>(): MyQueue<T> { const storage = new Map<bigint, T>(); let left = BigInt(0); let right = BigInt(0); function push(x: T): void { storage.set(right, x); right++; }
function pop(): T { const r = storage.get(left); storage.delete(left); left++; return r as T; }
function peek(): T { const r = storage.get(left); return r as T; }
function empty(): boolean { return left === right; } return { empty, peek, pop, push };}
Version Info