tinycodinglm / cp /cp-10045.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
1.15 kB
opencode trace
System You are an expert LeetCode problem solver. You solve problems efficiently with clean code.

You are an expert LeetCode problem solver. You solve problems efficiently with clean code.

User

Problem: Minimum Time Difference (Difficulty: Medium)
Tags: Array, Math, String, Sorting

Example 1:
Input: timePoints = ["23:59","00:00"]
Output: 1

Example 2:
Input: timePoints = ["00:00","23:59","00:00"]
Output: 0

Constraints:

  • 2 <= timePoints.length <= 2 * 10^4
  • timePoints[i] is in the format "HH:MM".
Assistant

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]))