problems(cpp): add “2390. Removing Stars From a String”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
10b6b3dd69
commit
5a62aba9c1
1 changed files with 20 additions and 0 deletions
20
problems/removing-stars-from-a-string.cpp
Normal file
20
problems/removing-stars-from-a-string.cpp
Normal 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() };
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue