题解 | 【模板】整数优先队列

【模板】整数优先队列

https://www.nowcoder.com/practice/a88e9711f7b04369982bbe8902278ae4

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        while (n-- > 0) {
            int op = in.nextInt();
            switch (op) {
                case 1:
                    int x = in.nextInt();
                    queue.offer(x);
                    break;

                case 2:
                    if (!queue.isEmpty())
                        System.out.println(queue.peek());
                    break;

                case 3:
                    if(!queue.isEmpty())
                        queue.poll();
                    break;
            }
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务