648. Removing Stars From a String

MediumStackStackString

Given a string s containing letters and '*' characters, repeatedly remove each '*' together with the closest non-star character to its left. Return the resulting string after all stars are processed (it is guaranteed to be non-empty after removal or empty). The input is JSON {s}.

Input: JSON {s}.

Output: String — the string after removing stars.

Examples

Example 1
Input: {"s":"leet**cod*e"}
Output: lecoe
Explanation: Each star deletes the previous character.
Example 2
Input: {"s":"erase*****"}
Output: 
Explanation: Everything is erased.
Example 3
Input: {"s":"abc"}
Output: abc
Explanation: No stars.

Constraints

Asked by

IBMAmazonMicrosoftGoogle
Solve this problem in the editor →