forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
33 lines (33 loc) · 1.05 KB
/
Solution.cpp
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
class Solution {
public:
vector<string> removeComments(vector<string>& source) {
vector<string> ans;
string t;
bool blockComment = false;
for (auto& s : source) {
int m = s.size();
for (int i = 0; i < m; ++i) {
if (blockComment) {
if (i + 1 < m && s[i] == '*' && s[i + 1] == '/') {
blockComment = false;
++i;
}
} else {
if (i + 1 < m && s[i] == '/' && s[i + 1] == '*') {
blockComment = true;
++i;
} else if (i + 1 < m && s[i] == '/' && s[i + 1] == '/') {
break;
} else {
t.push_back(s[i]);
}
}
}
if (!blockComment && !t.empty()) {
ans.emplace_back(t);
t.clear();
}
}
return ans;
}
};