← 返回 bloomberg 的题目列表Decode an Encoded String with Nested Patterns
类型:online_judge
Problem
Given an encoded string s, decode it following these rules:
The encoding pattern is k[encoded_string], meaning encoded_string is repeated k times.
k is a positive integer and may have multiple digits.
encoded_string may be nested.
The input is guaranteed to have valid, matched brackets.
Return the decoded string.
Input
One line: string s
Output
One line: the decoded string
Constraints
1 <= len(s) <= 2 * 10^5
The decoded output length will not exceed 2 * 10^5
Examples
Input: "3[a]2[bc]" Output: "aaabcbc"
Input: "3[a2[c]]" Output: "accaccacc"
Example
Input
3[a]2[bc]
Output
aaabcbc