Skip to content

Commit 2072492

Browse files
committed
이예진: [PG] 42884 단속카메라_241115
1 parent 7441a2c commit 2072492

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Programmers/Level3/YJ_42884.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.Arrays;
2+
import java.util.Comparator;
3+
4+
public class YJ_42884 {
5+
public int solution(int[][] routes) {
6+
Arrays.sort(routes, Comparator.comparingInt(o -> o[0]));
7+
8+
int current = routes[0][1];
9+
int answer = 1;
10+
for(int i=1; i<routes.length; i++){
11+
if(current < routes[i][0]){
12+
answer++;
13+
current = routes[i][1];
14+
}else{ //current >= routes[i][0]
15+
current = Math.min(current, routes[i][1]);
16+
}
17+
}
18+
19+
return answer;
20+
}
21+
}

0 commit comments

Comments
 (0)