394. Decode String [Medium] 栈
394. Decode String

394. Decode String
class Solution(object):
def decodeString(self, s):
"""
:type s: str
:rtype: str
"""
stack = []
for i in s:
if i != ']':
stack.append(i)
else:
temp = []
while stack[-1] != '[':
t = stack.pop()
temp.append(t)
temp = temp[::-1]
stack.pop()
n_l = []
while stack and stack[-1] in '1234567890':
n_l.append(int(stack.pop()))
n_l = n_l[::-1]
n = 0
for i in n_l:
n = n * 10 + I
stack.extend(n*temp)
return ''.join(stack)
本文标题:394. Decode String [Medium] 栈
本文链接:https://www.haomeiwen.com/subject/frvhcctx.html
网友评论