Skip to content

Commit a22aa65

Browse files
authored
feat: [LeetCode #2390] Removing Stars From A String (#26)
Тип: Stack Сложность: medium Временная сложность: O(n) Пространственная сложность: O(n) - Ссылка: https://leetcode.com/problems/removing-stars-from-a-string/
1 parent 658a02e commit a22aa65

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/stack/__init__.py

Whitespace-only changes.

src/stack/removing_stars_from_a_string/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def removeStars(self, s: str) -> str:
3+
stack = []
4+
5+
for char in s:
6+
if char == "*":
7+
stack.pop()
8+
else:
9+
stack.append(char)
10+
11+
return "".join(stack)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
from src.stack.removing_stars_from_a_string.solution import (
3+
Solution,
4+
)
5+
6+
7+
@pytest.mark.parametrize(
8+
"s, expected",
9+
[
10+
("leet**cod*e", "lecoe"),
11+
("erase*****", ""),
12+
],
13+
)
14+
def test_remove_stars(s, expected):
15+
solution = Solution()
16+
assert solution.removeStars(s) == expected

0 commit comments

Comments
 (0)