-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path0722.cpp
More file actions
34 lines (34 loc) · 703 Bytes
/
0722.cpp
File metadata and controls
34 lines (34 loc) · 703 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
29
30
31
32
33
34
class Solution {
public:
vector<string> removeComments(vector<string>& source) {
bool in_comment = false;
vector<string> res;
string s;
for (auto& x : source) {
for (int i = 0; i < x.size(); ++i) {
string t{x.substr(i, 2)};
if (in_comment) {
if (t == "*/") {
in_comment = false;
++i;
}
continue;
}
if (t == "/*") {
++i;
in_comment = true;
continue;
}
if (t == "//") {
break;
}
s += x[i];
}
if (!in_comment && !s.empty()) {
res.emplace_back(s);
s.clear();
}
}
return res;
}
};