-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2375.cpp
More file actions
26 lines (24 loc) · 692 Bytes
/
2375.cpp
File metadata and controls
26 lines (24 loc) · 692 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
26
class Solution {
public:
string smallestNumber(string pattern) {
int n = pattern.size();
string res;
for (int i = 0; i <= n; ++i) res.push_back('0' + i + 1);
int index = 0;
while (index < n) {
if (pattern[index] == 'I') {
index++;
}
else {
int start = index;
while (index + 1 < n && pattern[index + 1] == 'D') {
index++;
}
int end = index;
reverse(res.begin() + start, res.begin() + end + 2);
index++;
}
}
return res;
}
};