From 5a62aba9c1dde144d6a81727a499f62612c76d91 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 11 Apr 2023 18:47:54 +0200 Subject: [PATCH] =?UTF-8?q?problems(cpp):=20add=20=E2=80=9C2390.=20Removin?= =?UTF-8?q?g=20Stars=20From=20a=20String=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- problems/removing-stars-from-a-string.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 problems/removing-stars-from-a-string.cpp diff --git a/problems/removing-stars-from-a-string.cpp b/problems/removing-stars-from-a-string.cpp new file mode 100644 index 0000000..cb659ff --- /dev/null +++ b/problems/removing-stars-from-a-string.cpp @@ -0,0 +1,20 @@ +#include +#include + +class Solution { +public: + std::string removeStars(const std::string& s) + { + std::vector without_stars; + + for (auto c : s) { + if (c == '*') { + without_stars.pop_back(); + } else { + without_stars.push_back(c); + } + } + + return std::string { without_stars.begin(), without_stars.end() }; + } +};