2224. Minimum Number of Operations to Convert Time Easy

@problem@discussion
#String#Greedy



1/**
2 * [2224] Minimum Number of Operations to Convert Time
3 *
4 * You are given two strings current and correct representing two 24-hour times.
5 * 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.
6 * In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.
7 * Return the minimum number of operations needed to convert current to correct.
8 *  
9 * Example 1:
10 * 
11 * Input: current = "02:30", correct = "04:35"
12 * Output: 3
13 * Explanation:
14 * We can convert current to correct in 3 operations as follows:
15 * - Add 60 minutes to current. current becomes "03:30".
16 * - Add 60 minutes to current. current becomes "04:30".
17 * - Add 5 minutes to current. current becomes "04:35".
18 * It can be proven that it is not possible to convert current to correct in fewer than 3 operations.
19 * Example 2:
20 * 
21 * Input: current = "11:00", correct = "11:01"
22 * Output: 1
23 * Explanation: We only have to add one minute to current, so the minimum number of operations needed is 1.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	current and correct are in the format "HH:MM"
29 * 	current <= correct
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/
35// discuss: https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn convert_time(current: String, correct: 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_2224() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.