java.lang.Object
g2301_2400.s2390_removing_stars_from_a_string.Solution

public class Solution extends Object
2390 - Removing Stars From a String.<p>Medium</p> <p>You are given a string <code>s</code>, which contains stars <code>*</code>.</p> <p>In one operation, you can:</p> <ul> <li>Choose a star in <code>s</code>.</li> <li>Remove the closest <strong>non-star</strong> character to its <strong>left</strong> , as well as remove the star itself.</li> </ul> <p>Return <em>the string after <strong>all</strong> stars have been removed</em>.</p> <p><strong>Note:</strong></p> <ul> <li>The input will be generated such that the operation is always possible.</li> <li>It can be shown that the resulting string will always be unique.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;leet**cod*e&rdquo;</p> <p><strong>Output:</strong> &ldquo;lecoe&rdquo;</p> <p><strong>Explanation:</strong> Performing the removals from left to right:</p> <ul> <li> <p>The closest character to the 1<sup>st</sup> star is &lsquo;t&rsquo; in &ldquo;lee**<ins>t</ins>****cod*e&rdquo;. s becomes &ldquo;lee*cod*e&rdquo;.</p> </li> <li> <p>The closest character to the 2<sup>nd</sup> star is &lsquo;e&rsquo; in &ldquo;le**<ins>e</ins>***cod*e&rdquo;. s becomes &ldquo;lecod*e&rdquo;.</p> </li> <li> <p>The closest character to the 3<sup>rd</sup> star is &lsquo;d&rsquo; in &ldquo;leco**<ins>d</ins>***e&rdquo;. s becomes &ldquo;lecoe&rdquo;.</p> </li> </ul> <p>There are no more stars, so we return &ldquo;lecoe&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;erase*****&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> The entire string is removed, so we return an empty string.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> consists of lowercase English letters and stars <code>*</code>.</li> <li>The operation above can be performed on <code>s</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details