funcdecodeString(sstring)string{idx:=0varstk[]stringgetDigits:=func()string{num:=""fors[idx]>='0'&&s[idx]<='9'{num+=string(s[idx])idx++}returnnum}foridx<len(s){ifs[idx]>='0'&&s[idx]<='9'{stk=append(stk,getDigits())}elseifs[idx]==']'{varsub[]stringforstk[len(stk)-1]!="["{sub=append(sub,stk[len(stk)-1])stk=stk[:len(stk)-1]}// reverse character
fori:=0;i<len(sub)/2;i++{sub[i],sub[len(sub)-i-1]=sub[len(sub)-i-1],sub[i]}// pop [ from stack
stk=stk[:len(stk)-1]// get repeat count
cnt,_:=strconv.Atoi(stk[len(stk)-1])// pop repeat count from stack
stk=stk[:len(stk)-1]// repeat sub and push result to stack
stk=append(stk,strings.Repeat(strings.Join(sub,""),cnt))idx++}else{stk=append(stk,string(s[idx]))idx++}}returnstrings.Join(stk,"")}