We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f461a4 commit cd99779Copy full SHA for cd99779
1 file changed
String/722.Remove-Comments/722.Remove-Comments.cpp
@@ -0,0 +1,42 @@
1
+class Solution {
2
+public:
3
+ vector<string> removeComments(vector<string>& source)
4
+ {
5
+ vector<string>result;
6
+ bool comment=false;
7
+ string s;
8
+
9
+ for (int i=0; i<source.size(); i++)
10
11
+ for (int j=0; j<source[i].size(); j++)
12
13
+ if (!comment && j+1<source[i].size() && source[i].substr(j,2)=="//")
14
+ break;
15
+ else if (!comment && j+1<source[i].size() && source[i].substr(j,2)=="/*")
16
17
+ comment=true;
18
+ j++;
19
+ }
20
+ else if (comment && j+1<source[i].size() && source[i].substr(j,2)=="*/")
21
22
+ comment=false;
23
24
25
+ else if (!comment)
26
27
+ s.push_back(source[i][j]);
28
29
30
31
32
+ if (!comment && s.size()>0)
33
34
+ result.push_back(s);
35
+ s.clear();
36
37
38
39
40
+ return result;
41
42
+};
0 commit comments