강의로 돌아가기

### 테스트3 파라미터 값을 볼수 있나요??

코드채점시 테스트3 만 통과를 못하는데
테스트 케이스가 무엇으로 되어있는지 궁금하네요
아래는 테스트 코드입니다.

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.PriorityQueue;

class Solution {
public int solution(String[] lines) {
Traffic traffic = new Traffic(lines.length);

traffic.makeTimeList(lines);
return traffic.getMaxTPS();
}
}

class Traffic {
long[] startTime;
long[] endTime;
PriorityQueue notUsedOverOneSec;
int numOfLines;
int maxTPS;

public Traffic(int numOfLines) {
this.numOfLines = numOfLines;
this.startTime = new long[numOfLines];
this.endTime = new long[numOfLines];
this.notUsedOverOneSec = new PriorityQueue<>();
this.maxTPS = 0;
}

class Node implements Comparable {
int index;
long startTime;

public Node(int index, long startTime) {
this.index = index;
this.startTime = startTime;
}

@Override
public int compareTo(Node o) {
return Long.compare(startTime, o.startTime);
}
}

public void makeTimeList(String[] lines) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss.SSS);
for (int i = 0, length = lines.length; i < length; i++) {
try {
Date date = simpleDateFormat.parse(lines[i].substring(0,23));
long endTime = date.getTime();
Double timeSpent = Double.parseDouble(lines[i].substring(24).replace(s,""));
long startTime = endTime - (long)(timeSpent*1000) + 1;

this.startTime[i] = startTime;
this.endTime[i] = endTime;
} catch (ParseException e) {
e.printStackTrace();
}
}
}

public int getMaxTPS() {
int indexOfStartCount = 0;
int indexOfLastThreeSec = 0;
int curTPS = 0;

if (indexOfStartCount == 0) {
long startCountTime = endTime[indexOfStartCount];
long endCountTime = startCountTime + 999;
long limitPossibleTime = startCountTime + 2999;

while (indexOfLastThreeSec < numOfLines && endTime[indexOfLastThreeSec] <= endCountTime) {
curTPS++;
indexOfLastThreeSec++;
}

while (indexOfLastThreeSec < numOfLines && endTime[indexOfLastThreeSec] <= limitPossibleTime) {
if (startTime[indexOfLastThreeSec] <= endCountTime) {
curTPS++;
}
else {
notUsedOverOneSec.offer(new Node(indexOfLastThreeSec, startTime[indexOfLastThreeSec]));
}
indexOfLastThreeSec++;
}

maxTPS = Math.max(curTPS, maxTPS);
}

for (indexOfStartCount = 1; indexOfStartCount < endTime.length; indexOfStartCount++) {
curTPS--;
long startCountTime = endTime[indexOfStartCount];
long endCountTime = startCountTime + 999;
long limitPossibleTime = startCountTime + 2999;

while (!notUsedOverOneSec.isEmpty() && notUsedOverOneSec.peek().startTime <= endCountTime) {
notUsedOverOneSec.poll();
curTPS++;
}

while (indexOfLastThreeSec < numOfLines && endTime[indexOfLastThreeSec] <= limitPossibleTime) {
if (startTime[indexOfLastThreeSec] <= endCountTime) {
curTPS++;
}
else {
notUsedOverOneSec.offer(new Node(indexOfLastThreeSec, startTime[indexOfLastThreeSec]));
}
indexOfLastThreeSec++;
}

maxTPS = Math.max(curTPS, maxTPS);
}

return maxTPS;
}
}

##### 1 개의 답변

파이썬으로 작성했을때 테스트3의 경우 [2016-09-15 01:00:04.001 2.0s, 2016-09-15 01:00:07.000 2s] 로 나오는데요.

2016-09-15 01:00:04.001 2.0s ->
01:00:02.001 ~ 01:00:04.001
2016-09-15 01:00:07.000 2s ->
01:00:05.000 ~ 01:00:07.00