1
# Runtime: 38 ms (Top 74.6%) | Memory: 16.44 MB (Top 25.3%)
2

3

4
class Solution:
5
def removeComments(self, source: List[str]) -> List[str]:
6
ans, inComment = [], False
7
new_str = ""
8
for c in source:
9
if not inComment:
10
new_str = ""
11
i, n = 0, len(c)
12
# inComment, we find */
13
while i < n:
14
if inComment:
15
if c[i : i + 2] == "*/" and i + 1 < n:
16
i += 2
17
inComment = False
18
continue
19
i += 1
20
# not in Comment, we find /* // and common character
21
else:
22
if c[i : i + 2] == "/*" and i + 1 < n:
23
i += 2
24
inComment = True
25
continue
26
if c[i : i + 2] == "//" and i + 1 < n:
27
break
28
new_str += c[i]
29
i += 1
30
if new_str and not inComment:
31
ans.append(new_str)
32

33
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0