Decode String
Problem statement
Given a valid encoded string s, return its decoded form.
An encoded group has the form k[encodedString], meaning that encodedString is repeated exactly k times. Groups may be nested, and a repeat count may contain multiple digits.
The unencoded text contains lowercase English letters. Digits appear only as repeat counts immediately before bracketed groups.
Function
decodeString(s: String) → StringExamples
Example 1
s = "3[a]2[bc]"return = "aaabcbc"Repeat a three times and bc twice, then concatenate the two decoded parts.
Example 2
s = "3[a2[c]]"return = "accaccacc"The inner group becomes cc, so the outer group repeats acc three times.
Example 3
s = "2[abc]3[cd]ef"return = "abcabccdcdcdef"Decode the two adjacent repeated groups, then retain the trailing literal ef.
Constraints
1 <= s.length <= 30.scontains lowercase English letters, digits, and square brackets.sis a valid encoding with well-formed brackets.- Every repeat count is between
1and300. - The decoded output length does not exceed
10^5.