class Solution {
public:
string dfs(string s,int &idx)
{
string str;
while(idx<s.size())
{
if(s[idx]==']')
{
idx++;
return str;
}
else if(s[idx]>'0'&&s[idx]<='9')
{
string num;
while(s[idx]>='0'&&s[idx]<='9') num+=s[idx++];
if(s[idx]=='[')
{
int cnt=stoi(num);
string t=dfs(s,++idx);
while(cnt--)
str=str+t;
}
}
else
str+=s[idx++];
}
return str;
}
string decodeString(string s) {
int u=0;
return dfs(s,u);
}
};
标签:string,idx,Leetcode394,解码,&&,字符串
From: https://www.cnblogs.com/tangxibomb/p/17574134.html