2645. Minimum Additions to Make Valid String Medium
1/**
2 * [2645] Minimum Additions to Make Valid String
3 *
4 * Given a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.
5 * A string is called valid if it can be formed by concatenating the string "abc" several times.
6 *
7 * <strong class="example">Example 1:
8 *
9 * Input: word = "b"
10 * Output: 2
11 * Explanation: Insert the letter "a" right before "b", and the letter "c" right next to "b" to obtain the valid string "abc".
12 *
13 * <strong class="example">Example 2:
14 *
15 * Input: word = "aaa"
16 * Output: 6
17 * Explanation: Insert letters "b" and "c" next to each "a" to obtain the valid string "abcabcabc".
18 *
19 * <strong class="example">Example 3:
20 *
21 * Input: word = "abc"
22 * Output: 0
23 * Explanation: word is already valid. No modifications are needed.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= word.length <= 50
29 * word consists of letters "a", "b" and "c" only.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-additions-to-make-valid-string/
35// discuss: https://leetcode.com/problems/minimum-additions-to-make-valid-string/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn add_minimum(word: String) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2645() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.