인프런 피부과
문제
나의 풀이
import java.util.*;
public class Dermatology {
public static int getTime(String time) {
int h = Integer.parseInt(time.split(":")[0]);
int m = Integer.parseInt(time.split(":")[1]);
return h * 60 + m;
}
public static int solution(int laser[], String enter[]) {
int answer = 0;
int n = enter.length;
int inList[][] = new int[n][2];
for(int i = 0; i < n; i++) {
int a = getTime(enter[i].split(" ")[0]);
int b = Integer.parseInt(enter[i].split(" ")[1]);
inList[i][0] = a;
inList[i][1] = b;
}
Queue<Integer> q = new LinkedList<>();
q.offer(inList[0][1]);
int ft = inList[0][0];
int pos = 1;
for(int t = ft; t <= 1200; t++) {
if(pos < n && t == inList[pos][0]) {
if(q.isEmpty() && t > ft) {
ft = t;
}
q.offer(inList[pos][1]);
pos++;
}
if(t == ft && !q.isEmpty()) {
int index = q.poll();
ft += laser[index];
}
answer = Math.max(answer, q.size());
}
return answer;
}
public static void main(String[] args) {
System.out.println(Dermatology.solution(new int[]{30, 20, 25, 15}, new String[]{"10:23 0", "10:40 3", "10:42 2", "10:52 3", "11:10 2"}));
}
}
결과