Problem · String
Decode String
Learn this problemProblem statement
Given a valid encoded string s, return its fully decoded form.
The encoding rule is k[encoded_string], meaning that the content inside the brackets is repeated exactly k times. Encoded groups may be nested, and adjacent literal or encoded groups are concatenated.
For this exercise, assume repetition counts are positive decimal integers and literal characters are lowercase English letters.
Function
decodeString(s: String) → StringExamples
Example 1
s = "3[a2[c]]"return = "accaccacc"The inner group 2[c] becomes cc, so the outer group is 3[acc].
Example 2
s = "2[abc]3[cd]ef"return = "abcabccdcdcdef"Decode the two repeated groups independently, then append the literal suffix ef.
Constraints
1 <= s.length <= 10^5sis a valid encoding with balanced brackets.- Every repetition count is in
[1, 300]. - Literal characters are lowercase English letters.
- The decoded output length is at most
10^5.