java.lang.Object
g1201_1300.s1209_remove_all_adjacent_duplicates_in_string_ii.Solution

public class Solution extends Object
1209 - Remove All Adjacent Duplicates in String II.<p>Medium</p> <p>You are given a string <code>s</code> and an integer <code>k</code>, a <code>k</code> <strong>duplicate removal</strong> consists of choosing <code>k</code> adjacent and equal letters from <code>s</code> and removing them, causing the left and the right side of the deleted substring to concatenate together.</p> <p>We repeatedly make <code>k</code> <strong>duplicate removals</strong> on <code>s</code> until we no longer can.</p> <p>Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;, k = 2</p> <p><strong>Output:</strong> &ldquo;abcd&rdquo;</p> <p><strong>Explanation:</strong> There&rsquo;s nothing to delete.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;deeedbbcccbdaa&rdquo;, k = 3</p> <p><strong>Output:</strong> &ldquo;aa&rdquo;</p> <p><strong>Explanation:</strong></p> <p>First delete &ldquo;eee&rdquo; and &ldquo;ccc&rdquo;, get &ldquo;ddbbbdaa&rdquo;</p> <p>Then delete &ldquo;bbb&rdquo;, get &ldquo;dddaa&rdquo;</p> <p>Finally delete &ldquo;ddd&rdquo;, get &ldquo;aa&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;pbbcggttciiippooaais&rdquo;, k = 2</p> <p><strong>Output:</strong> &ldquo;ps&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>2 <= k <= 10<sup>4</sup></code></li> <li><code>s</code> only contains lower case English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • removeDuplicates

      public String removeDuplicates(String s, int k)