diff --git a/src/stack/__init__.py b/src/stack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/stack/removing_stars_from_a_string/__init__.py b/src/stack/removing_stars_from_a_string/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/stack/removing_stars_from_a_string/solution.py b/src/stack/removing_stars_from_a_string/solution.py new file mode 100644 index 0000000..0eeb932 --- /dev/null +++ b/src/stack/removing_stars_from_a_string/solution.py @@ -0,0 +1,11 @@ +class Solution: + def removeStars(self, s: str) -> str: + stack = [] + + for char in s: + if char == "*": + stack.pop() + else: + stack.append(char) + + return "".join(stack) diff --git a/tests/test_removing_stars_from_a_string.py b/tests/test_removing_stars_from_a_string.py new file mode 100644 index 0000000..fe25a19 --- /dev/null +++ b/tests/test_removing_stars_from_a_string.py @@ -0,0 +1,16 @@ +import pytest +from src.stack.removing_stars_from_a_string.solution import ( + Solution, +) + + +@pytest.mark.parametrize( + "s, expected", + [ + ("leet**cod*e", "lecoe"), + ("erase*****", ""), + ], +) +def test_remove_stars(s, expected): + solution = Solution() + assert solution.removeStars(s) == expected