美文网首页Leetcode
Leetcode 1736. Latest Time by Re

Leetcode 1736. Latest Time by Re

作者: SnailTyan | 来源:发表于2021-07-19 09:23 被阅读0次

    文章作者:Tyan
    博客:noahsnail.com  |  CSDN  |  简书

    1. Description

    Latest Time by Replacing Hidden Digits

    2. Solution

    解析:枚举所有可能情况,替换对应的?即可。

    • Version 1
    class Solution:
        def maximumTime(self, time: str) -> str:
            result = ''
            if time[0] == '?':
                if time[1] < '4' or time[1] == '?':
                    result += '2'
                else:
                    result += '1'
            else:
                result += time[0]
    
            if time[1] == '?':
                result += '9' if result[-1] < '2' else '3'
            else:
                result += time[1]
    
            result += ':'
            result += '5' if time[3] == '?' else time[3]
            result += '9' if time[4] == '?' else time[4]
            return result
    

    Reference

    1. https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/

    相关文章

      网友评论

        本文标题:Leetcode 1736. Latest Time by Re

        本文链接:https://www.haomeiwen.com/subject/zmjgultx.html