腾讯笔试4.26 二维top k

public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        List<Integer> lenlist = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        for (int i=0;i<N;i++){
            int len = sc.nextInt();
            lenlist.add(len);
            for (int j=0;j<len;j++){
                list.add(sc.nextInt());
            }
        }
        list.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) {
                return o2.compareTo(o1);
            }
        });
        for (int i =0;i<K;i++)
            System.out.print(list.get(i)+" ");
        sc.close();
    }

居然这都A了 纯暴力#腾讯笔试##腾讯##笔试题目#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 17:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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