forked from lzl124631x/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths1.cpp
More file actions
25 lines (25 loc) · 604 Bytes
/
Copy paths1.cpp
File metadata and controls
25 lines (25 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
private:
string dfs(string &s, int &i) {
string ans;
while (i < s.size() && s[i] != ']') {
if (isdigit(s[i])) {
int n = 0;
while (isdigit(s[i])) n = n * 10 + s[i++] - '0';
++i;
string part = dfs(s, i);
++i;
while (n--) ans += part;
} else {
ans.push_back(s[i++]);
}
}
return ans;
}
public:
string decodeString(string s) {
string ans;
int i = 0;
return dfs(s, i);
}
};