Demo entry 6645149

python

   

Submitted by anonymous on Oct 09, 2017 at 09:48
Language: Python 3. Code size: 887 Bytes.

from collections import defaultdict
import sys
class Solution(object):
    def findMinDifference(self, timePoints):
        """
        :type timePoints: List[str]
        :rtype: int
        """
        expanded_time = defaultdict(int)
        for element in timePoints:
            time_split = element.split(':')
            hour = int(time_split[0])
            minute = int(time_split[1])
            key = hour * 60 + minute
            if key in expanded_time:
                return 0
            else:
                expanded_time[key] += 1
        time_list = sorted(expanded_time.keys())
        min_time_diff = sys.maxint
        for i in range(1, len(time_list)):
            min_time_diff = min(min_time_diff, time_list[i] - time_list[i-1])
        min_time_diff = min(min_time_diff, time_list[0] + 1440 - time_list[-1])
        return min_time_diff

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).