2025-09-22 17:10

Status: adult

Tags: leetcode leetcode-easy google strings arrays Removing Stars From a String Leetcode

Clear Digits

Code

class Solution(object):
    def clearDigits(self, s):
        """
        :type s: str
        :rtype: str
        """
 
 
        stack = []
 
        for char in s:
            if not char.isdigit():
                stack.append(char)
            else:
                stack.pop()
        
        return "".join(stack)

Explanation

  1. Just like

    Removing Stars From a String

    2024-12-20 17:34

    Status: child leetcode leetcode-medium

    Tags: stack arrays Leetcode

    Removing Stars From a String

    Code

    class Solution(object):
        def removeStars(self, s):
            """
            :type s: str
            :rtype: str
            """
     
            stack = []
     
            for letter in s:
                if letter != "*":
                    stack.append(letter)
                else:
                    stack.pop(-1)
            return "".join(stack)
            
        # Time Complexity: O(n)
        # Space Complexitty: O(n)

    Explanation

    • way to simple don’t even need to explain

    References

    Link to original
    except it’s digits instead of stars.

References

Me