1209. Remove All Adjacent Duplicates in String II Medium
1/**
2 * [1209] Remove All Adjacent Duplicates in String II
3 *
4 * You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.
5 * We repeatedly make k duplicate removals on s until we no longer can.
6 * Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.
7 *
8 * Example 1:
9 *
10 * Input: s = "abcd", k = 2
11 * Output: "abcd"
12 * Explanation: There's nothing to delete.
13 * Example 2:
14 *
15 * Input: s = "deeedbbcccbdaa", k = 3
16 * Output: "aa"
17 * Explanation:
18 * First delete "eee" and "ccc", get "ddbbbdaa"
19 * Then delete "bbb", get "dddaa"
20 * Finally delete "ddd", get "aa"
21 * Example 3:
22 *
23 * Input: s = "pbbcggttciiippooaais", k = 2
24 * Output: "ps"
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= s.length <= 10^5
30 * 2 <= k <= 10^4
31 * s only contains lowercase English letters.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/
37// discuss: https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn remove_duplicates(s: String, k: i32) -> String {
43 String::new()
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_1209() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.