标签:turn solution sel find ret == pen ted app
其实暴力也能解,因为就4*4*4*4种
class Solution: def findNext(self, char, nums): i = 0 while i < len(nums): if nums[i] == char: if i != len(nums) - 1: return nums[i + 1] else: return None i += 1 return None def nextClosestTime(self, time: str) -> str: nums = [] for i in [0, 1, 3, 4]: if time[i] not in nums: nums.append(time[i]) nums = sorted(nums) c4 = self.findNext(time[4], nums) if c4 and int(time[3] + c4) < 60: return time[:4] + c4 c3 = self.findNext(time[3], nums) if c3 and int(c3 + nums[0]) < 60: return time[:3] + c3 + nums[0] c1 = self.findNext(time[1], nums) if c1 and int(time[0] + c1) <= 24: return time[0] + c1 + ‘:‘ + nums[0] + nums[0] c0 = self.findNext(time[0], nums) if c0 and int(c0 + nums[0]) <= 24: return c0 + nums[0] + ‘:‘ + nums[0] + nums[0] return nums[0] + nums[0] + ‘:‘ + nums[0] + nums[0]
标签:turn solution sel find ret == pen ted app
原文地址:https://www.cnblogs.com/lautsie/p/12244495.html