leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0394.cpp (776B)


0 class Solution {
1 public:
2 string decodeString(string s) {
3 stack<int> is;
4 stack<string> ss;
6 ss.push("");
7 for (int i = 0; i < s.size(); i++) {
8 if (isdigit(s[i])) {
9 int res = 0;
10 do {
11 res *= 10;
12 res += s[i] - '0';
13 } while (isdigit(s[++i]));
14 is.push(res);
15 ss.push("");
16 } else if (s[i] == ']') {
17 string res = "";
18 while (is.top()--)
19 res += ss.top();
20 is.pop();
21 ss.pop();
22 ss.top() += res;
23 } else {
24 ss.top() += s[i];
25 }
26 }
28 return ss.top();
29 }
30 };