class Solution:
# https://m.blog.naver.com/hyj5419/221960681691 참조
def decodeString(self, s: str) -> str:
ans = ''
stack = []
for char in s:
if char != ']':
stack.append(char)
else:
# 알파벳 추출
temp_str = ''
while stack and stack[-1] != '[':
temp_str += stack.pop()
temp_str = temp_str[::-1]
stack.pop() # '[' 제거
# 숫자 추출
num = ''
while stack and stack[-1].isdigit():
num += stack.pop()
num = int(num[::-1])
for t in list(num * temp_str):
stack.append(t)
return ''.join(stack)