commit c5d6dff82d4fd9c7291be0d802bad4b7ebcc8074
parent ebb7598f67630b4635caca530d517d57552ef404
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 1 Dec 2024 23:47:10 +0100
1 Random Problem
Diffstat:
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/Problems/0722.cpp b/Problems/0722.cpp
@@ -0,0 +1,32 @@
+class Solution {
+ public:
+ vector<string> removeComments(vector<string> &source) {
+ vector<string> res = {""};
+ bool block = false;
+
+ for (const auto &l : source) {
+ int j = 0, i;
+
+ for (i = 0; i < size(l); i++) {
+ if (!block && l[i] == '/' && l[i + 1] == '/')
+ break;
+ else if (!block && l[i] == '/' && l[i + 1] == '*') {
+ if (i != j) res.back() += l.substr(j, i - j);
+
+ i++; // prevent /*/ as close
+ block = true;
+ } else if (block && l[i] == '*' && l[i + 1] == '/') {
+ j = i + 2;
+ i++; // prevent */* as open
+ block = false;
+ }
+ }
+
+ if (!block && i != j) res.back() += l.substr(j, i - j);
+ if (!block && !res.back().empty()) res.push_back("");
+ }
+
+ if (res.back().empty()) res.pop_back();
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -551,6 +551,7 @@ reference and a base for solving problems.
| 0718 | Medium | [Maximum Length of Repeated Subarray](Problems/0718.cpp) |
| 0719 | Hard | [Find K-th Smallest Pair Distance](Problems/0719.cpp) |
| 0720 | Medium | [Longest Word in Dictionary](Problems/0720.cpp) |
+| 0722 | Medium | [Remove Comments](Problems/0722.cpp) |
| 0724 | Easy | [Find Pivot Index](Problems/0724.cpp) |
| 0725 | Medium | [Split Linked List in Parts](Problems/0725.cpp) |
| 0726 | Hard | [Number of Atoms](Problems/0726.cpp) |