Skip to content
LC-0539 Medium LeetCode

539. Minimum Time Difference

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Array, Math, String, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(n)

class Solution(object):
    def findMinDifference(self, timePoints):
        """
        :type timePoints: List[str]
        :rtype: int
        """
        minutes = map(lambda x: int(x[:2]) * 60 + int(x[3:]), timePoints)
        minutes.sort()
        return min((y - x) % (24 * 60)  \
                   for x, y in zip(minutes, minutes[1:] + minutes[:1]))

Solution from kamyu104/LeetCode-Solutions · MIT