Demo entry 6645138

python

   

Submitted by anonymous on Oct 09, 2017 at 09:44
Language: Python 3. Code size: 1.1 kB.

class Solution(object):
    def findMinDifference(self, timePoints):
        """
        :type timePoints: List[str]
        :rtype: int
        """
        timePoints.sort()
        timePoints.append(timePoints[0])
        length = len(timePoints)
        minDiff = 24*60
        sHour, sMinute = timePoints[0].split(":")
        sHour = int(sHour)
        sMinute = int(sMinute)
            
        for i in range(1,length):
            hour, minute = timePoints[i].split(":")
            hour = int(hour)
            minute = int(minute)
            if hour < 12 and sHour-hour > 12:
                hour = hour + 24
            if sHour < 12 and hour-sHour > 12:
                sHour = sHour + 24
            if hour < sHour:
                diff = (sHour-hour)*60 + sMinute - minute
            elif hour > sHour:
                diff = (hour-sHour)*60 + minute - sMinute
            else:
                diff = abs(minute-sMinute)
            minDiff = diff if diff < minDiff else minDiff

            sHour = hour
            sMinute = minute
        return minDiff

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).