Search

๊น€๋‚˜์˜

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
3720
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
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
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ