From d089ebf2faec218a62e57b9c6315cd267cbfd81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=92=D0=B0=D1=81?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2?= Date: Sun, 23 Nov 2025 19:45:27 +0300 Subject: [PATCH] feat: [LeetCode #2390] Removing Stars From A String MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Тип: Stack Сложность: medium Временная сложность: O(n) Пространственная сложность: O(n) - Ссылка: https://leetcode.com/problems/removing-stars-from-a-string/ --- src/stack/__init__.py | 0 .../removing_stars_from_a_string/__init__.py | 0 .../removing_stars_from_a_string/solution.py | 11 +++++++++++ tests/test_removing_stars_from_a_string.py | 16 ++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 src/stack/__init__.py create mode 100644 src/stack/removing_stars_from_a_string/__init__.py create mode 100644 src/stack/removing_stars_from_a_string/solution.py create mode 100644 tests/test_removing_stars_from_a_string.py 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