코테 기초
queue.poll()을 Print하는 것은, 그 작업이 시행되었기도 하다
서버관리자 페페
2022. 12. 7. 23:01
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// ISC - L1
Scanner sc = new Scanner(System.in);
int CN = sc.nextInt();
// PRe
PriorityQueue<Integer> myQueue = new PriorityQueue<>(((o1, o2) -> {
int first_abs = Math.abs(o1);
int second_abs = Math.abs(o2);
if (first_abs == second_abs)
return o1 > 02 ? 1 : -1;
else
return first_abs - second_abs;
}));
// L2 + Operating Heap
for (int i = 0; i < CN; i++) {
int code = sc.nextInt();
if (code == 0) {
if (!myQueue.isEmpty()) {
myQueue.poll();
System.out.println(myQueue.poll());
} else {
System.out.println("0");
}
} else {
myQueue.add(code);
}
}
}
}
시행 코드 == 0 분기에서
println(myQueue.poll()); 위에 myQueue.poll()을 넣는 것은
중복 작업이 되는 것임(삭제할 것)