python


  • 0
    P
    from itertools import permutations
    
    class Solution(object):
        def sameDigits(self, x, y):
            for c in x:
                if c not in y:
                    return False
            return True
        
        def nextClosestTime(self, time):
            """
            :type time: str
            :rtype: str
            """
            digits = ''.join([time[0], time[1], time[3], time[4]])
            print(digits)
            original = digits
            while True:
                digits = int(digits)
                digits += 1
                
                if digits > 2359:
                    digits = 0            
                if digits%100 > 59:
                    # print('>>', digits)
                    digits += 100
                    digits -= 60
                    # print('>>', digits, '>>')              
                
                digits = str(digits).zfill(4)
                # print(digits)
                if self.sameDigits(digits, original):
                    digits = str(digits)
                    return digits[0]+digits[1]+':'+digits[2]+digits[3]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.