#2437
Number of Valid Clock Times
pupil · 505 · lc easy +27 · verified · 47.9% accepted · 306 likes · top 33%
Description
You are given a string time of length 5 in the format "HH:MM", where some digits may be replaced by '?'.
Count and return the number of valid 24-hour clock times that can be formed by replacing each '?' with a single digit.
Example 1:
Input: time = "?5:00"
Output: 2
Explanation: We can replace the ? with either a 0 or 1, producing "05:00" or "15:00". Note that we cannot replace it with a 2, since the time "25:00" is invalid. In total, we have two choices.
Example 2:
Input: time = "0?:0?"
Output: 100
Explanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.
Example 3:
Input: time = "??:??"
Output: 1440
Explanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.
Code
1
2
3