Design and implement a data structure for a compressed string iterator. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.
Implement the StringIterator class:
char next()Returns the next character if the original string still has uncompressed characters, otherwise returns a white space.boolean hasNext()Returnstrueif there is any letter needs to be uncompressed in the original string, otherwise returnsfalse.
Example 1:
Input:
["StringIterator", "next", "next", "next", "next", "next", "next", "hasNext", "next", "hasNext"]
[["N1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []]
Output:
[null, "N", "e", "e", "t", "C", "o", true, "d", true]
Explanation:
StringIterator stringIterator = new StringIterator("N1e2t1C1o1d1e1");
stringIterator.next(); // return "N"
stringIterator.next(); // return "e"
stringIterator.next(); // return "e"
stringIterator.next(); // return "t"
stringIterator.next(); // return "C"
stringIterator.next(); // return "o"
stringIterator.hasNext(); // return True
stringIterator.next(); // return "d"
stringIterator.hasNext(); // return TrueConstraints:
1 <= compressedString.length <= 1000compressedStringconsists of lower-case an upper-case English letters and digits.- The number of a single character repetitions in
compressedStringis in the range[1, 10⁹] - At most
100calls will be made tonextandhasNext.