class RangeTime {
int startTime;
int endTime;
}
public void f(List<RangeTime> rangeTimes) {
int[] onlineNums = new int[24 * 60 * 60];
int maxOnlineNum = 0;
int maxOnlineStart = 0, maxOnlineEnd = 0;
int maxOnlineNumLast = 0;
for (RangeTime rangeTime : rangeTimes) {
for (int i = rangeTime.startTime; i <= rangeTime.endTime; i++) {
onlineNums[i]++;
if (onlineNums[i] > maxOnlineNum) {
maxOnlineNum = onlineNums[i];
}
}
}
for (int i = 0; i < 24 * 60 * 60; i++) {
if (onlineNums[i] == maxOnlineNum) {
int lastTime = 1;
int startTime = i;
while (onlineNums[i] == onlineNums[i+1]) {
i++;
lastTime++;
}
int endTime = i;
if (lastTime > maxOnlineNumLast) {
maxOnlineStart = startTime;
maxOnlineEnd = endTime;
}
}
}
}
最大在线人数,最大在线人数的最长在线时间区间是什么
最新推荐文章于 2023-07-07 00:21:19 发布