Leetcode Problem 604. Design Compressed String Iterator

604. Design Compressed String Iterator

Leetcode Solutions

Demand-Computation Approach

  1. Initialize a pointer ptr to 0 and a count num to 0.
  2. For next(), if num is 0, parse the next character and its count from the compressed string. Otherwise, decrement num and return the current character.
  3. For hasNext(), return true if num is greater than 0 or ptr is not at the end of the string; otherwise, return false.
UML Thumbnail

Pre-Computation Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...