

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
615

被折叠的 条评论
为什么被折叠?



