• 카테고리

    질문 & 답변
  • 세부 분야

    알고리즘 · 자료구조

  • 해결 여부

    해결됨

해당 문제 다른 풀이에 대한 질문입니다.

23.08.01 23:45 작성 조회수 227

0

import java.io.*;
import java.util.*;

class Time implements Comparable<Time> {
    int startTime, endTime;

    public Time(int startTime, int endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    public int compareTo(Time time) {
        if (this.endTime == time.endTime) {
            return this.startTime - time.startTime;
        } else {
            return this.endTime - time.endTime;
        }
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        List<Time> times = new ArrayList<>();

        StringTokenizer st;
        int startTime, endTime;
        for (int i = 0; i < n; i++) {
            st = new StringTokenizer(br.readLine());
            startTime = Integer.parseInt(st.nextToken());
            endTime = Integer.parseInt(st.nextToken());

            times.add(new Time(startTime, endTime));
        }

        System.out.print(solution(times));
    }

    private static int solution(List<Time> times) {
        int answer = 0;
        int endTime = 0;
        int count = 1;

        Collections.sort(times);

        for (Time time : times) {
            if (time.startTime < endTime) {
                count++;
            } else {
                answer = Math.max(answer, count);
                count = 1;
                endTime = time.endTime;
            }
        }

        return answer;
    }
}

 

이렇게 로직을 구현했는데, 왜 오답 처리되는지 궁금합니다.
다른 예외 케이스가 존재할까요?

답변 1

답변을 작성해보세요.

0

안녕하세요^^

아래 입력케이스가 나오지 않습니다. 그리고 채점사이트에서 "오답입니다"를 클릭하면 오답이 나오는 케이스를 확인할 수 있습니다.

10

17 28

6 30

1 27

19 38

4 46

23 30

35 43

26 45

21 31

11 44

 

정답은 9입니다.