


维护一个放数字的栈,一个放字母的栈
遇到[把数字和字母入栈,遇到]把当前字母循环加上数字栈头遍的字母栈头
cpp
class Solution {
public:
string decodeString(string s) {
string ans="";
stack<int>sz;
stack<string>zm;里面是string 还是Char,要看你定义往里加的字符是哪个类型
int count=0;
for(auto& x:s){
if(isdigit(x))
count=10*count+x-'0';
else if(x=='['){
sz.push(count);
count=0;
zm.push(ans);
ans=""; }
else if(isalpha(x))
ans+=x;
else if(x==']'){
int n=sz.top();
string cur=zm.top();
sz.pop();
zm.pop();
while(n--){
cur+=ans; }
ans=cur;} }
return ans;}};