2528. Number of Valid Clock Times
My accepted Python solution to LeetCode problem 2528, Number of Valid Clock Times, running in 67ms.
- Difficulty: Easy
- Python
- Runtime 67ms
- Memory 17.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 67ms, memory 17.1MB, accepted 2026-01-01.
class Solution:
def countTime(self, time: str) -> int:
count = 0
for h in range(24):
for m in range(60):
t = f"{h:02d}:{m:02d}"
if all(t[i] == time[i] or time[i] == '?' for i in range(5)):
count += 1
return count