假设给你一个function,可以返回工人过去时间工作的时间间隔,比如1-4点,5-9点,
要求判断工人是否可以继续工作,工人工作的条件是: worker can work up to 12
hours total before an 8 hour contiguous break
c***g 发帖数: 472
2
我提供的代码是这样的,希望大家提宝贵意见。
static int MINI_GAP = 8;
static int MINI_TOTAL = 12;
bool canDriverLogIn(userId){
vector intervals = getShifts(userId);
int total = 0 ;
int gap = 0;
int current = getCurrentTime();
int size = intervals.size();
if(size <= 0 ) return true;
for(int i = 0; i < size; i++) {
int gap = (current + 24 - intervals[i].end) % 24;
int total += intervals[i].end - intervals[i].start;
if( gap >= MINI_GAP && total <= MINI_TOTAL) return true;
if(total > MINI_TOTAL ) return false;
current = intervals[i].end;
}
return true;
}
【在 c***g 的大作中提到】 : 假设给你一个function,可以返回工人过去时间工作的时间间隔,比如1-4点,5-9点, : 要求判断工人是否可以继续工作,工人工作的条件是: worker can work up to 12 : hours total before an 8 hour contiguous break
l*********8 发帖数: 4642
3
题意不清啊。 给几个test cases吧?
【在 c***g 的大作中提到】 : 假设给你一个function,可以返回工人过去时间工作的时间间隔,比如1-4点,5-9点, : 要求判断工人是否可以继续工作,工人工作的条件是: worker can work up to 12 : hours total before an 8 hour contiguous break