腾讯笔试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了 纯暴力#腾讯笔试##腾讯##笔试题目#
全部评论

相关推荐

AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务