deno.land / x / masx200_leetcode_test@10.6.5 / design-compressed-string-iterator / 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
export default class StringIterator { #gen: Generator<string, void, unknown>; #result: IteratorResult<string, void>; constructor(compressedString: string) { this.#gen = RLEGenerator(compressedString); this.#result = this.#gen.next(); } next() { const value = this.#result.value; if (typeof value === "undefined") return ""; this.#result = this.#gen.next(); return value; } hasNext() { return !this.#result.done; }}function* RLEGenerator(encoding: string) { for (let i = 0; i < encoding.length; i += 2) { const count = Number(encoding[i + 1]); for (let j = 0; j < count; j++) { yield encoding[i]; } }}
masx200_leetcode_test

Version Info

Tagged at
a year ago