← 返回 bytedance 的题目列表Remove All Adjacent Duplicates in String II
类型:online_judge
Given a string s and an integer k, you can remove k adjacent characters when they are the same. Repeat the process until you cannot do so anymore. Return the final string after all possible removals.
Input:
A string s with the length range [1, 10^5].
An integer k with the range [2, 10^4].
Output:
The final string without k adjacent identical characters after reordering.
Example 1:
Input: s = "abcd", k = 2
Output: "abcd"
Example 2:
Input: s = "deeedbbcccbdaa", k = 3
Output: "aa"
Write the code to achieve this functionality.
Example
Input
abcd
2