← 返回 microsoft 的题目列表Largest Time for Given Digits
类型:online_judge
Problem: Largest Time for Given Digits
You are given an integer array digits of length 4, where every element is in [0, 9]. Use each digit exactly once to form a 24-hour time string in the format HH:MM.
Return the largest valid time that can be formed.
A valid time satisfies:
00 <= HH <= 23
00 <= MM <= 59
Leading zeros must be preserved, e.g. 04:00 is valid.
If no valid time can be formed, output -1.
Input Format
One line containing four integers representing digits.
Output Format
Print the largest valid time in HH:MM format, or -1 if none exists.
Examples
Input:
1 2 3 4
Output:
23:41
Input:
5 5 5 5
Output:
-1
Constraints
digits.length == 4
0 <= digits[i] <= 9
Example
Input
1 2 3 4
Output
23:41