949. Largest Time for Given Digits Medium

@problem@discussion
#String#Enumeration



1/**
2 * [949] Largest Time for Given Digits
3 *
4 * Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.
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 * Return the latest 24-hour time in "HH:MM" format. If no valid time can be made, return an empty string.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = [1,2,3,4]
11 * Output: "23:41"
12 * Explanation: The valid 24-hour times are "12:34", "12:43", "13:24", "13:42", "14:23", "14:32", "21:34", "21:43", "23:14", and "23:41". Of these times, "23:41" is the latest.
13 * 
14 * Example 2:
15 * 
16 * Input: arr = [5,5,5,5]
17 * Output: ""
18 * Explanation: There are no valid 24-hour times as "55:55" is not valid.
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	arr.length == 4
24 * 	0 <= arr[i] <= 9
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/largest-time-for-given-digits/
30// discuss: https://leetcode.com/problems/largest-time-for-given-digits/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn largest_time_from_digits(arr: Vec<i32>) -> String {
36        String::new()
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_949() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.