Class Solution
java.lang.Object
g1201_1300.s1209_remove_all_adjacent_duplicates_in_string_ii.Solution
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 = “abcd”, k = 2</p>
<p><strong>Output:</strong> “abcd”</p>
<p><strong>Explanation:</strong> There’s nothing to delete.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “deeedbbcccbdaa”, k = 3</p>
<p><strong>Output:</strong> “aa”</p>
<p><strong>Explanation:</strong></p>
<p>First delete “eee” and “ccc”, get “ddbbbdaa”</p>
<p>Then delete “bbb”, get “dddaa”</p>
<p>Finally delete “ddd”, get “aa”</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “pbbcggttciiippooaais”, k = 2</p>
<p><strong>Output:</strong> “ps”</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 Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
removeDuplicates
-