java.lang.Object
g1001_1100.s1047_remove_all_adjacent_duplicates_in_string.Solution

public class Solution extends Object
1047 - Remove All Adjacent Duplicates In String.<p>Easy</p> <p>You are given a string <code>s</code> consisting of lowercase English letters. A <strong>duplicate removal</strong> consists of choosing two <strong>adjacent</strong> and <strong>equal</strong> letters and removing them.</p> <p>We repeatedly make <strong>duplicate removals</strong> on <code>s</code> until we no longer can.</p> <p>Return <em>the final string after all such duplicate removals have been made</em>. It can be proven that the answer is <strong>unique</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abbaca&rdquo;</p> <p><strong>Output:</strong> &ldquo;ca&rdquo;</p> <p><strong>Explanation:</strong></p> <p>For example, in &ldquo;abbaca&rdquo; we could remove &ldquo;bb&rdquo; since the letters are adjacent and equal, and this is the only possible move.</p> <p>The result of this move is that the string is &ldquo;aaca&rdquo;, of which only &ldquo;aa&rdquo; is possible, so the final string is &ldquo;ca&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;azxxzy&rdquo;</p> <p><strong>Output:</strong> &ldquo;ay&rdquo;</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.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • removeDuplicates

      public String removeDuplicates(String s)