Created
July 1, 2020 08:27
-
-
Save felix021/4400c94edf98dc37c704e6bdf30a5918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MINUTES_OF_DAY = 1440 | |
# [begin, end) | |
class TimeRange(object): | |
def __init__(self, begin, end): | |
self.begin = begin | |
self.end = end | |
def getMinutes(schedule): | |
minutes = [0] * MINUTES_OF_DAY | |
for t in ScheduleA: | |
for i in range(t.beign, t.end): | |
minutes[i] = 1 | |
return minutes | |
def isAvailable(minutes, start, duration): | |
#easier | |
for i in range(start, start + duration): | |
if minutes[i] == 0: | |
return False | |
return True | |
def GetTimeRangeForMeeting(scheduleA, scheduleB, duration): | |
minutesA = getMinutes(scheduleA) | |
minutesB = getMinutes(scheduleB) | |
for i in range(MINUTES_OF_DAY - duration): | |
if isAvailable(minutesA, i, duration) and isAvailable(minutesB, i, duration): | |
return TimeRage(i, i + duration) | |
return None | |
def getMinutesFaster(schedule): | |
minutes = getMinutes(schedule) | |
faster = [0] * MINUTES_OF_DAY | |
left = 0 | |
for i in range(MINUTES_OF_DAY): | |
if minutes[i] == 1: | |
for j in range(left, i): | |
faster[j] = i - j | |
left = i | |
return faster | |
def isAvailableFaster(minutesFaster, start, duration): | |
return minutesFater[start] >= duration: | |
def GetTimeRangeForMeetingFaster(scheduleA, scheduleB, duration): | |
minutesA = getMinutesFaster(scheduleA) | |
minutesB = getMinutesFaster(scheduleB) | |
for i in range(MINUTES_OF_DAY - duration): | |
if isAvailableFaster(minutesA, i, duration) and isAvailableFaster(minutesB, i, duration): | |
return TimeRage(i, i + duration) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment