|
3 | 3 | [中文文档](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README.md)
|
4 | 4 |
|
5 | 5 | ## Description
|
6 |
| -None |
| 6 | +<p>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.</p> |
| 7 | + |
| 8 | +<p>Implement the StringIterator class:</p> |
| 9 | + |
| 10 | +<ul> |
| 11 | + <li><code>next()</code> Returns <strong>the next character</strong> if the original string still has uncompressed characters, otherwise returns a <strong>white space</strong>.</li> |
| 12 | + <li><code>hasNext()</code> Returns true if there is any letter needs to be uncompressed in the original string, otherwise returns <code>false</code>.</li> |
| 13 | +</ul> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong>Example 1:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input</strong> |
| 20 | +["StringIterator", "next", "next", "next", "next", "next", "next", "hasNext", "next", "hasNext"] |
| 21 | +[["L1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []] |
| 22 | +<strong>Output</strong> |
| 23 | +[null, "L", "e", "e", "t", "C", "o", true, "d", true] |
| 24 | + |
| 25 | +<strong>Explanation</strong> |
| 26 | +StringIterator stringIterator = new StringIterator("L1e2t1C1o1d1e1"); |
| 27 | +stringIterator.next(); // return "L" |
| 28 | +stringIterator.next(); // return "e" |
| 29 | +stringIterator.next(); // return "e" |
| 30 | +stringIterator.next(); // return "t" |
| 31 | +stringIterator.next(); // return "C" |
| 32 | +stringIterator.next(); // return "o" |
| 33 | +stringIterator.hasNext(); // return True |
| 34 | +stringIterator.next(); // return "d" |
| 35 | +stringIterator.hasNext(); // return True |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li><code>1 <= compressedString.length <= 1000</code></li> |
| 43 | + <li><code>compressedString</code> consists of lower-case an upper-case English letters and digits.</li> |
| 44 | + <li>The number of a single character repetitions in <code>compressedString</code> is in the range <code>[1, 10^9]</code></li> |
| 45 | + <li>At most <code>100</code> calls will be made to <code>next</code> and <code>hasNext</code>.</li> |
| 46 | +</ul> |
| 47 | + |
7 | 48 |
|
8 | 49 |
|
9 | 50 | ## Solutions
|
|
0 commit comments