第一行输入一个n代表有n场演讲(n <= 200)下面n行需要输入两个整数 start、end代表会议开始时间和结束时间,其中(1<= start<=end <= 24)
输出一个整数,这个整数代表最多的宣讲场次
3 1 10 11 20 10 11
3
3 6 12 7 8 8 9
2
import java.util.*; public class Main { private static class Node{ public int start; public int end; public Node(int start,int end){ this.start=start; this.end=end; } } public static void main(String[] args){ Scanner input=new Scanner(System.in); int lineCount=input.nextInt(); if(lineCount<=0){ System.out.println(0); return; } Node[] array=new Node[lineCount]; for(int i=0;i<lineCount;i++){ array[i]=new Node(input.nextInt(),input.nextInt()); } Arrays.sort(array,(e1,e2)->e1.start-e2.start); Arrays.sort(array,(e1,e2)->e1.end-e2.end); int start=array[0].start; int count=0; for(Node node: array){ if(start<=node.start){ count++; start=node.end; } } System.out.println(count); } }