Class Solution
-
- All Implemented Interfaces:
public final class Solution3114 - Latest Time You Can Obtain After Replacing Characters\.
Easy
You are given a string
srepresenting a 12-hour format time where some of the digits (possibly none) are replaced with a"?".12-hour times are formatted as
"HH:MM", whereHHis between00and11, andMMis between00and59. The earliest 12-hour time is00:00, and the latest is11:59.You have to replace all the
"?"characters inswith digits such that the time we obtain by the resulting string is a valid 12-hour format time and is the latest possible.Return the resulting string.
Example 1:
Input: s = "1?:?4"
Output: "11:54"
Explanation: The latest 12-hour format time we can achieve by replacing
"?"characters is"11:54".Example 2:
Input: s = "0?:5?"
Output: "09:59"
Explanation: The latest 12-hour format time we can achieve by replacing
"?"characters is"09:59".Constraints:
s.length == 5s[2]is equal to the character":".All characters except
s[2]are digits or"?"characters.The input is generated such that there is at least one time between
"00:00"and"11:59"that you can obtain after replacing the"?"characters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringfindLatestTime(String s)-
-
Method Detail
-
findLatestTime
final String findLatestTime(String s)
-
-
-
-