← 返回 instacart 的题目列表Decode an Encoded String
类型:online_judge
Given an encoded string s with the rule:
The encoding format is k[encoded_string], meaning encoded_string is repeated exactly k times.
k is a positive integer.
encoded_string may itself contain further encoded patterns (nesting is allowed).
Decode s and return the decoded string.
Requirements
Correctly handle nested encodings.
s contains only digits, letters, and square brackets [ and ].
Examples
Input: s = "3[a]2[bc]" Output: "aaabcbc"
Input: s = "3[a2[c]]" Output: "accaccacc"
Constraints (typical interview setting)
1 <= len(s) <= 1e4
Decoded output length <= 1e5
Test cases
Example
Input
3[a]2[bc]
Output
aaabcbc