604. Design Compressed String Iterator

Design an iterator for a run-length encoded string. The encoded string is a sequence of a letter followed by a positive count, for example "L3M2" expands to "LLLMM" and "A2B1C3" expands to "AABCCC".

Implement the StringIterator class:

  • StringIterator(String compressedString) initializes the iterator with the encoded string.
  • next() returns the next character and advances the iterator. If no characters remain, return a single space " ".
  • hasNext() returns true if at least one character remains, otherwise false.
Examples
Input: [["StringIterator","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next"],[["A2"],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]]
Output: [null,true,"A",true,"A",false," ",false," ",false," ",false," ",false," ",false," "]
Hints

604. Design Compressed String Iterator

Design an iterator for a run-length encoded string. The encoded string is a sequence of a letter followed by a positive count, for example `"L3M2"` expands to `"LLLMM"` and `"A2B1C3"` expands to `"AABCCC"`.