Skip to content
LC-2390 Medium LeetCode

2390. Removing Stars From a String

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 78% Topics: String, Stack, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

# stack
class Solution(object):
    def removeStars(self, s):
        """
        :type s: str
        :rtype: str
        """
        result = []
        for c in s:
            if c == '*':
                result.pop()
            else:
                result.append(c)
        return "".join(result)

Solution from kamyu104/LeetCode-Solutions · MIT