🙆♀️ 정답 풀이
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[][] arr = new int[N][2];
StringTokenizer st;
for(int i=0;i<N;i++){
st = new StringTokenizer(br.readLine());
arr[i][0] = Integer.parseInt(st.nextToken());
arr[i][1] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if(o1[1] == o2[1]){
return Integer.compare(o1[0],o2[0]);
}
return Integer.compare(o1[1],o2[1]);
}
});
int cnt = 1;
int start = arr[0][0];
int end = arr[0][1];
for(int idx=1;idx<N;idx++){
if(end<=arr[idx][0]){
cnt++;
end = arr[idx][1];
}
}
System.out.println(cnt);
}
}