Decode String
Given an encoded string where the encoding rule is k[encoded_string], meaning the encoded_string inside the brackets is repeated exactly k times, return the fully decoded string. Brackets may be nested, k is a positive integer, and the original data contains no digits (digits only appear as repeat counts).
Open official problem prompt ↗Expand a compressed, possibly nested run-length notation into the literal string it represents.
Like opening nested Russian dolls: each time you open a bracket you set the current doll aside, work on the smaller one inside, then place the finished inner doll back into the one you set aside.
- Input
- s = "3[a2[c]]"
- Output
- "accaccacc"
- Why
- The inner 2[c] expands to "cc", making "acc", and the outer 3[...] repeats "acc" three times.
1 <= s.length <= 30s consists of lowercase English letters, digits, and square brackets '[]'s is guaranteed to be a valid inputAll integers are in the range [1, 300]The decoded string may be much longer than s