#1736
Latest Time by Replacing Hidden Digits
pupil · 505 · lc easy +27 · verified · 43.7% accepted · 403 likes · top 25%
Description
You are given a string time in hh:mm format where some digits are '?'. Valid times range from 00:00 to 23:59. Replace each '?' to produce the latest possible valid time, and return it.
Example 1:
Input: time = "2?:?0"
Output: "23:50"
Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.
Example 2:
Input: time = "0?:3?"
Output: "09:39"
Example 3:
Input: time = "1?:22"
Output: "19:22"
Code
1
2
3