题解 | #活动安排#

活动安排

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);
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
希望奇迹发生的布莱克...:真的是 现在卷实习就是没苦硬吃
点赞 评论 收藏
分享
陈逸轩1205:才105 哥们在养生呢
点赞 评论 收藏
分享
Lorn的意义:你这种岗位在中国现在要么牛马天天加班,要么关系户进去好吃好喝,8年时间,真的天翻地覆了,对于资本来说你就说一头体力更好的牛马,哎,退伍没有包分配你真的亏了。
点赞 评论 收藏
分享
测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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