class Solution:
def decodeString(self, s: str) -> str:
l=[0]
return self.dp(s,l)
def dp(self,s,l):
res=''
n=len(s)
while(l[0]<n and s[l[0]]!=']'):
if s[l[0]]<'0' or s[l[0]]>'9':
res+=s[l[0]]
l[0]+=1
else:
cont=0
while s[l[0]]>='0' and s[l[0]]<='9':
cont=cont*10+int(s[l[0]])
l[0]+=1
l[0]+=1
t=self.dp(s,l)
l[0]+=1
for c in range(cont):
res+=t
return res
博客展示了一段Python代码,定义了一个名为Solution的类,其中包含decodeString和dp两个方法。通过动态规划的方式对字符串进行解码,在dp方法中根据字符类型进行不同处理,最终实现字符串的解码功能。
1124

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



