394. Decode String
https://leetcode.com/problems/decode-string/
Python
from collections import deque
class Solution:
def decodeString(self, s: str) -> str:
stack = []
for c in range(len(s)):
if s[c] != ']':
stack.append(s[c])
continue
num, letters = deque(), deque()
while stack[-1] != '[':
letters.appendleft(stack.pop())
stack.pop()
while stack and stack[-1].isdigit():
num.appendleft(stack.pop())
stack.append(int(''.join(num)) * ''.join(letters))
return "".join(stack)