importjava.util.*;classSolution{publicString[]solution(String[][]plans){String[]answer=newString[plans.length];intanswer_count=0;Queue<String>q_name=newLinkedList<>();Queue<Integer>q_time=newLinkedList<>();// plans 정렬Arrays.sort(plans,newComparator<String[]>(){@Overridepublicintcompare(String[]arr1,String[]arr2){String[]time1=arr1[1].split(":");String[]time2=arr2[1].split(":");inthourCompare=Integer.parseInt(time1[0])-Integer.parseInt(time2[0]);intminuteCompare=Integer.parseInt(time1[1])-Integer.parseInt(time2[1]);returnhourCompare!=0?hourCompare:minuteCompare;}});// 시작 시간 정하기intcurTime=toMin(plans[0]);// 현재 시각StringcurPlan=plans[0][0];// 현재 과제명intremainTime=Integer.parseInt(plans[0][2]);// 현재 과제 남은 시간intcount=1;// 대기 중인 과제 순서Stack<String>s_String=newStack<>();// 잠시 멈춘 과제명Stack<Integer>s_Int=newStack<>();// 잠시 멈춘 과제 남은 시간// 진행while(answer_count<plans.length){curTime++;remainTime--;if(remainTime==0){// 시간이 다 되면answer[answer_count]=curPlan;answer_count++;curPlan="";if(curTime==toMin(plans[count])){// 다음 과제 시간이라면curPlan=plans[count][0];remainTime=Integer.parseInt(plans[count][2]);count++;if(count==plans.length){count=0;}}elseif(!s_String.empty()){// 잠시 멈춘 과제가 있다면curPlan=s_String.pop();remainTime=s_Int.pop();}}elseif(curTime==toMin(plans[count])){// 다음 과제를 시작해야 한다면// 저장if(!curPlan.equals("")){s_String.push(curPlan);s_Int.push(remainTime);}curPlan=plans[count][0];remainTime=Integer.parseInt(plans[count][2]);count++;if(count==plans.length){count=0;}}}returnanswer;}publicstaticinttoMin(String[]strs){String[]time=strs[1].split(":");returnInteger.parseInt(time[0])*60+Integer.parseInt(time[1]);}}