2957. Remove Adjacent Almost-Equal Characters Medium
1/**
2 * [2957] Remove Adjacent Almost-Equal Characters
3 *
4 * You are given a 0-indexed string word.
5 * In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.
6 * Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.
7 * Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: word = "aaaaa"
12 * Output: 2
13 * Explanation: We can change word into "a<u>c</u>a<u>c</u>a" which does not have any adjacent almost-equal characters.
14 * It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: word = "abddez"
19 * Output: 2
20 * Explanation: We can change word into "<u>y</u>bd<u>o</u>ez" which does not have any adjacent almost-equal characters.
21 * It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
22 * <strong class="example">Example 3:
23 *
24 * Input: word = "zyxyxyz"
25 * Output: 3
26 * Explanation: We can change word into "z<u>a</u>x<u>a</u>x<u>a</u>z" which does not have any adjacent almost-equal characters.
27 * It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= word.length <= 100
33 * word consists only of lowercase English letters.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/remove-adjacent-almost-equal-characters/
39// discuss: https://leetcode.com/problems/remove-adjacent-almost-equal-characters/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn remove_almost_equal_characters(word: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2957() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.