2844. Minimum Operations to Make a Special Number Medium

@problem@discussion
#Math#String#Greedy#Enumeration



1/**
2 * [2844] Minimum Operations to Make a Special Number
3 *
4 * You are given a 0-indexed string num representing a non-negative integer.
5 * In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
6 * Return the minimum number of operations required to make num special.
7 * An integer x is considered special if it is divisible by 25.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: num = "2245047"
12 * Output: 2
13 * Explanation: Delete digits num[5] and num[6]. The resulting number is "22450" which is special since it is divisible by 25.
14 * It can be shown that 2 is the minimum number of operations required to get a special number.
15 * <strong class="example">Example 2:
16 * 
17 * Input: num = "2908305"
18 * Output: 3
19 * Explanation: Delete digits num[3], num[4], and num[6]. The resulting number is "2900" which is special since it is divisible by 25.
20 * It can be shown that 3 is the minimum number of operations required to get a special number.
21 * <strong class="example">Example 3:
22 * 
23 * Input: num = "10"
24 * Output: 1
25 * Explanation: Delete digit num[0]. The resulting number is "0" which is special since it is divisible by 25.
26 * It can be shown that 1 is the minimum number of operations required to get a special number.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= num.length <= 100
32 * 	num only consists of digits '0' through '9'.
33 * 	num does not contain any leading zeros.
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/minimum-operations-to-make-a-special-number/
39// discuss: https://leetcode.com/problems/minimum-operations-to-make-a-special-number/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn minimum_operations(num: 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_2844() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.