https://www.cnblogs.com/grandyang/p/5849037.html
class Solution { public: string decodeString(string s) { string res = ""; int length = s.size(); stack<int> num; stack<string> result; int number = 0; for(int i = 0;i < length;i++){ if(s[i] >= '0' && s[i] <= '9') number = number*10 + s[i] - '0'; else if(s[i] == '['){ num.push(number); number = 0; result.push(res); res.clear(); } else if(s[i] == ']'){ int k = num.top(); num.pop(); for(int j = 0;j < k;j++) result.top() += res; res = result.top(); result.pop(); } else res += s[i]; } return res; } };