We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7441a2c commit 2072492Copy full SHA for 2072492
Programmers/Level3/YJ_42884.java
@@ -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