题目:
分析:只说一句,在外面加一层1【 。。】使得初始问题一般化。
代碼:
class Solution:
def decodeString(self, s: str) -> str:
x = 0
s = '1['+s+']'
def f() -> str:
nonlocal x
c=0
# 取数字
while s[x].isnumeric():
c = c*10 + int(s[x])
x+=1
x+=1 # [
s2 = ''
while s[x]!=']':
if s[x].isnumeric():
s2 += f()
else :
s2 += s[x]
x=x+1
return s2*c
return f()