Latest Time by Replacing Hidden Digits LeetCode solution in Python

1
class Solution:
2
def maximumTime(self, time: str) -> str:
3
memo = {"0": "9", "1": "9", "?": "3", "2": "3"}
4

5
answer = ""
6
for idx, val in enumerate(time):
7
if val == "?":
8
if idx == 0:
9
if time[idx + 1] == "?":
10
answer += "2"
11

12
else:
13
if int(time[idx + 1]) >= 4:
14
answer += "1"
15

16
else:
17
answer += "2"
18

19
if idx == 1:
20
answer += memo[time[idx - 1]]
21

22
if idx == 3:
23
answer += "5"
24

25
if idx == 4:
26
answer += "9"
27

28
else:
29
answer += val
30

31
return answer

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0