problems(cpp): add “2390. Removing Stars From a String”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-04-11 18:47:54 +02:00
parent 10b6b3dd69
commit 5a62aba9c1
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,20 @@
#include <string>
#include <vector>
class Solution {
public:
std::string removeStars(const std::string& s)
{
std::vector<char> 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() };
}
};