394. Decode String
Practice Decode String for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
The input uses the rule k[text], meaning text written k times in a row. Brackets can be nested. Return the fully expanded string.
Example
s = "3[a]2[bc]" -> "aaabcbc"
s = "3[a2[c]]" -> "accaccacc"
Constraints
- 1 <= s.length <= 30
scontains lowercase letters, digits and square brackets, and is always well formed- Every
kis a positive integer between 1 and 300; digits only appear as repeat counts - The output length is at most 10^5