728x90
https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters
class Solution:
def findLatestTime(self, s: str) -> str:
result = ''
for i, c in enumerate(s):
if c == '?' and i == 0:
if s[1] <= '1' or s[1] == '?':
result += '1'
else:
result += '0'
elif c == '?' and i == 1:
if s[0] == '1' or s[0] == '?':
result += '1'
else:
result += '9'
elif c == '?' and i == 3:
result += "5"
elif c == '?' and i == 4:
result += '9'
else:
result += c
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2000. Reverse Prefix of Word (0) | 2024.05.02 |
---|---|
[Leetcode] 404. Sum of Left Leaves (0) | 2024.04.14 |
[Leetcode] 3110. Score of a String (0) | 2024.04.13 |
[Leetcode] 2073. Time Needed to Buy Tickets (0) | 2024.04.09 |
[Leetcode] 1700. Number of Students Unable to Eat Lunch (0) | 2024.04.08 |