본문 바로가기

IT/코딩테스트

[Leetcode] 3114. Latest Time You Can Obtain After Replacing Characters

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