[プログラマー]コードテスト練習-貪欲な3級管制カメラ



Solution.java

import java.util.*;

class Solution {
    public int solution(int[][] routes) {
        int answer = 1;
        
        Arrays.sort(routes, Comparator.comparingInt(o -> o[0])); // 차량 진입 순서대로 정렬
        
        int out = 30000;
        
        for (int[] route : routes) {
            if (route[1] < out) {
                out = route[1];
            }
            else if (route[0] > out) {
                answer++;
                out = route[1];
            }
        }
        
        return answer;
    }
}
出典:プログラマーコードテスト練習、https://programmers.co.kr/learn/challenges