题解 | #活动安排#

活动安排

https://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        LinkedList<int[]> queue = new LinkedList<>();
        sc.nextLine();
        int end = 0;
        int count = 0;
        while(sc.hasNextLine()){
            String[] str = sc.nextLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            queue.add(new int[]{a,b});
        }
        Collections.sort(queue,(s1,s2)->s1[1]-s2[1]);
        while(!queue.isEmpty())
        {
            int[] e = queue.poll();
            if(e[0]>=end){
                count++;
                end = e[1];
            }

        }
        System.out.println(count);
    }
}
全部评论

相关推荐

就只能3个月,但是要求长期全职实习
Swaying:你确实是能长期实习啊,但是你那时候有事也没啥办法嘛
点赞 评论 收藏
分享
北漂的牛马人:211佬,包进的,可能是系统问题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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