deno.land / x / masx200_leetcode_test@10.6.5 / dui-lie-de-zui-da-zhi-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
31
32
33
class MaxQueue { #a: number[] = [];
#b: number[] = []; constructor() {}
max_value(): number { if (this.#a.length === 0) return -1;
return this.#b[0] ?? -1; }
push_back(value: number): void { while (this.#a.length && value > this.#b[this.#b.length - 1]) { this.#b.pop(); } this.#a.push(value); this.#b.push(value); }
pop_front(): number { if (this.#a.length === 0) return -1; const value = this.#a[0];
if (this.#a[0] === this.#b[0]) { this.#b.shift(); } this.#a.shift(); return value; }}export default MaxQueue;
masx200_leetcode_test

Version Info

Tagged at
a year ago