Definition at line 5 of file main.cpp.
◆ decodeString()
| string Solution::decodeString |
( |
string |
s | ) |
|
|
inline |
Definition at line 8 of file main.cpp.
9 {
10 stack<pair<int, string>> pairs;
11 int multiplier = 0;
12 string current_string = "";
13
14 for (char el : s)
15 {
16 if (isdigit(el))
17 multiplier = multiplier * 10 + (el - '0');
18 else if (el == '[')
19 {
20 pairs.push({multiplier, current_string});
21 multiplier = 0;
22 current_string = "";
23 }
24 else if (el == ']')
25 {
26 auto [prev_multiplier, prev_string] = pairs.top();
27 pairs.pop();
28 string constructed = "";
29 for (int i = 0; i < prev_multiplier; ++i)
30 constructed += current_string;
31 current_string = prev_string + constructed;
32 }
33 else
34 current_string += el;
35 }
36 return current_string;
37 }
Referenced by main().
The documentation for this class was generated from the following file: