-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3170.cpp
More file actions
29 lines (28 loc) · 757 Bytes
/
3170.cpp
File metadata and controls
29 lines (28 loc) · 757 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
27
28
class Solution {
public:
string clearStars(string s) {
vector<vector<int>> hash(26);
int n = s.size();
for (int i = 0; i < n; ++i) {
if (s[i] == '*') {
s[i] = 'N';
for (int j = 0; j < 26; ++j) {
if (hash[j].size() > 0) {
int idx = hash[j].back();
s[idx] = 'N';
hash[j].pop_back();
break;
}
}
}
else {
hash[s[i] - 'a'].push_back(i);
}
}
string res = "";
for (auto& c : s) {
if (c != 'N') res.push_back(c);
}
return res;
}
};