394. 字符串解码 - 力扣(LeetCode)
class Solution:
def decodeString(self, s: str) -> str:
stack = []
num = 0
curr_str = ""
for char in s:
if char.isdigit():
num = num * 10 + int(char)
elif char == '[':
stack.append((curr_str, num))
curr_str, num = "", 0
elif char == ']':
last_str, repeat = stack.pop()
curr_str = last_str + curr_str * repeat
else:
curr_str += char
return curr_str