|
์ฝ๋ ์์ฑํ๊ธฐ
import java.util.*;
public class Printer {
public int solution(int[] priorities, int location) {
List<PrintJob> printlist = new ArrayList<PrintJob>();
for (int i = 0; i < priorities.length; i++)
printlist.add(new PrintJob(i,priorities[i]));
int answer = 0;
while(!printlist.isEmpty()){
// 0๋ฒ์ ๊บผ๋ด์ max priority๊ฐ ์๋๋ฉด ๋ค์ ๋์ ๋ฃ๋๋ค.
PrintJob job = printlist.remove(0);
if (printlist.stream().anyMatch(otherJob ->job.priority < otherJob.priority)){
printlist.add(job);
}else {
//max priority์ด๋ฉด ๋ด๊ฐ ์ฐพ๋ job์ด ๋ง๋์ง ํ์ธ
answer++;
if (location == job.location)
break;
}
}
return answer;
}
class PrintJob{
int priority;
int location;
public PrintJob(int location, int priority) {
this.location = location;
this.priority = priority;
}
}
public static void main(String[] args) {
Printer printer = new Printer();
int [] priorities = {1,1,9,1,1,1};
System.out.println(printer.solution(priorities,0));
}
}
Java
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ