115. Unsquash
A compression tool stores a string as a list of pairs: a lowercase letter followed directly by the number of times it repeats, written in decimal. The number is at least 1 and may have several digits. You receive such a code and must rebuild the original text.
Return the decoded string. For example, the code b2c1 expands to bbc. Build the answer with a single left-to-right scan; the decoded text never has more than 10^5 characters.
Example 1
- Input:
- code = "h3i1"
- Output:
- "hhhi"
- Explanation:
h repeats three times and i once, giving hhhi.
Example 2
- Input:
- code = "z11q2"
- Output:
- "zzzzzzzzzzzqq"
- Explanation:
The count 11 has two digits: eleven z characters followed by two q characters.
Constraints
2 ≤ code.length ≤ 105
code is a valid list of pairs: a lowercase letter followed by a count from 1 to 105
The decoded string has at most 105 characters
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(n + m)
- Space
- O(m)