인프런 커뮤니티 질문&답변
코드 질문
작성
·
260
0
package 결혼식;
import java.util.*;
class Time implements Comparable<Time>{
public int s, e;
Time(int s, int e){
this.s = s;
this.e = e;
}
public int compareTo(Time o) {
return this.s - o.s;
}
}
public class Main {
public int solution(ArrayList<Time> arr, int n) {
int answer = 0;
int cnt = 0;
Collections.sort(arr);
for(int i=0; i<n; i++) {
Time tmp = arr.get(i);
for(Time x : arr) {
if(x.s < tmp.s && tmp.s < x.e || tmp.e < x.e && x.s < tmp.e) {
cnt++;
}
}
answer = Math.max(cnt, answer);
cnt = 0;
}
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
ArrayList<Time> arr = new ArrayList<>();
for(int i=0; i<n; i++) {
int s = scan.nextInt();
int e = scan.nextInt();
arr.add(new Time(s,e));
}
System.out.print(T.solution(arr, n));
}
}
이중for문을 이용해서 코드를 짰는데 답은 맞게 나오는 거 같은데 검사 돌렸을때 오답으로 나오는데 어느 부분이 문제인지 궁금합니다!
퀴즈
회의실 배정 문제에서 최대 회의 수를 얻기 위해 회의를 정렬하는 주요 기준은 무엇일까요?
시작 시간 오름차순
종료 시간 오름차순
회의 시간 길이 오름차순
종료 시간 내림차순





