File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 19
19
617|[ Merge Two Binary Trees] ( ./0617-merge-two-binary-trees.js ) |Easy|
20
20
648|[ Replace Words] ( ./0648-replace-words.js ) |Medium|
21
21
686|[ Repeated String Match] ( ./0686-repeated-string-match.js ) |Easy|
22
+ 722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
22
23
739|[ Daily Temperatures] ( ./0739-daily-temperatures.js ) |Medium|
23
24
791|[ Custom Sort String] ( ./0791-custom-sort-string.js ) |Medium|
24
25
804|[ Unique Morse Code Words] ( ./0804-unique-morse-code-words.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 722. Remove Comments
3
+ * https://leetcode.com/problems/remove-comments/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a C++ program, remove comments from it. The program source is an array where source[i] is the i-th
7
+ * line of the source code. This represents the result of splitting the original source code string by the
8
+ * newline character \n.
9
+ * In C++, there are two types of comments, line comments, and block comments.
10
+ * The string // denotes a line comment, which represents that it and rest of the characters to the right
11
+ * of it in the same line should be ignored.
12
+ * The string /* denotes a block comment, which represents that all characters until the next
13
+ * (non-overlapping) occurrence of should be ignored.
14
+ * It is guaranteed that every open block comment will eventually be closed, so /* outside of a line or block
15
+ * comment always starts a new comment.
16
+ * Finally, implicit newline characters can be deleted by block comments.
17
+ * After removing the comments from the source code, return the source code in the same format.
18
+ */
19
+
20
+ /**
21
+ * @param {string[] } source
22
+ * @return {string[] }
23
+ */
24
+ var removeComments = function ( source ) {
25
+ return source . join ( '\n' ) . replace ( / \/ \* .* ?\* \/ | \/ \/ [ ^ \n ] + / gs, '' ) . split ( / \n / ) . filter ( Boolean ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments