import java.util.*;
class Solution {
public int solution(int[][] routes) {
int answer = 0;
Arrays.sort(routes,(o1,o2)-> o1[1]==o2[1] ? o1[0]-o2[0] : o1[1]-o2[1]);
int camera=routes[0][1];
answer++;
for(int i=0; i<routes.length; i++){
if(routes[i][0] <= camera){
continue;
}
else if(routes[i][0] > camera){
answer++;
camera = routes[i][1];
}
}
return answer;
// st et
// -20-15
// -18-13
// -14-5
// -5-3
}
}
2차원 배열 Arrays.sort()에서 람다를 이용해 본인의 요구대로 정렬할줄 안다면, 쉽게 풀수있는문제.
Arrays.sort(routes,(o1,o2)-> o1[1]==o2[1] ? o1[0]-o2[0] : o1[1]-o2[1]);
이런 식으로 람다를 이용해 2차원 배열을 정렬해주면 된다. 삼항연사자를 이용해주면 첫번째 정렬조건의 값이 같을 경우도 처리가능. 아주 간편하고 외우기도 쉽다. 굿.